Let's say there are several shapefiles in a folder. I would like to make a folder of each shapefile and zip those individual folder. This activity will help in uploading individual shapefile in ArcGIS online server. ArcGIS online server only accepts the zip folder of individual shapefile.
Here is the R code...
shp_file_names <- list.files("Shapefile zipped/", include.dirs = FALSE)
shp_uniq <- do.call("rbind", strsplit(shp_file_names, "\\."))[, 1]
shp_uniq <- unique(shp_uniq)
for (eachFile in shp_uniq) {
dir.create(paste0("shape_unzip/", eachFile))
shp_files <- list.files("Shapefile zipped/", pattern = eachFile)
file.copy(paste0("Shapefile zipped/", shp_files),
paste0("shape_unzip/", eachFile, "/", shp_files))
}
shp_folders <- list.files("shape_unzip/")
for (eachFolder in shp_folders) {
zipCmd <- paste0("zip -r ", paste0("shape_zip/", eachFolder), " .")
system(zipCmd, invisible = TRUE, show.output.on.console = FALSE)
}
No comments:
Post a Comment