Last active
July 27, 2016 23:09
-
-
Save cengel/4992a0766070cbfd74f305c105ce819f 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
## | |
## this snippet loops through a directory with rasters and crates polygons | |
## using a call to gdal_polygonize.py | |
## (for Mac, with kynchaos GDAL framework) | |
## | |
# make sure to not mess up the paths here! | |
setwd("root/dir") | |
indir <- "rasterdir-ending-with-slash/" | |
outdir <- "polydir-ending-with-slash/" | |
pth <- "/path/to/gdal_polygonize.py" | |
# let's do it | |
infiles <- list.files(indir) | |
outfiles <- sub(".asc", ".shp", infiles) # or replace .asc with .tif | |
dir.create(file.path(".", outdir), showWarnings = FALSE) | |
sapply(1:length(infiles), function(i) | |
system(paste(pth, paste0(indir, infiles[i]), "-f 'ESRI Shapefile'", paste0(outdir, outfiles[i])))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment