Last active
December 19, 2016 12:41
-
-
Save KarthiAru/73148ae994697249b41b1cedac2e090f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the layers from .kml file | |
layers <- ogrListLayers('bbmp.kml')[2:198] | |
i<-1 | |
# Get polygon from first layer | |
poly.data <- readOGR(dsn="bbmp.kml", layer=layers[1], encoding="utf-8", verbose = F) | |
n <- length(slot(poly.data, "polygons")) | |
poly.data <- spChFIDs(poly.data, as.character(i:(i+n-1))) | |
i <- i + n | |
# Combine remaining polygons with first polygon | |
timer_all <- Sys.time() | |
pb <- txtProgressBar(max=length(layers), style = 3) | |
options(warn=-1) # disable warnings | |
for (i in 2:length(layers)) { | |
temp.data <- readOGR(dsn="bbmp.kml", layer=layers[i], encoding="utf-8", verbose = F) | |
n <- length(slot(temp.data, "polygons")) | |
temp.data <- spChFIDs(temp.data, as.character(i:(i+n-1))) | |
i <- i + n | |
poly.data <- spRbind(poly.data,temp.data) | |
setTxtProgressBar(pb, i) | |
} | |
cat("***Process completed in",round(difftime(Sys.time(), timer_all, tz = "", units = "mins"),2),"min!***") | |
options(warn = 0) # re-enable warnings | |
close(pb) | |
# save combined polygons to a single .kml file | |
writeOGR(poly.data, dsn="blr.kml", layer="bangalore", driver="KML") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment