Skip to content

Instantly share code, notes, and snippets.

@hrwgc
Created November 2, 2012 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrwgc/3998011 to your computer and use it in GitHub Desktop.
Save hrwgc/3998011 to your computer and use it in GitHub Desktop.
gdal trace raster outlines
## run in a directory with many raster images containing nodata values that make their gdalinfo extents unreliable. output is a csv containing filename and data-containing extents, to be imported into postgis, sqlite, etc for running spatial queries.
## usage:
echo "file;GEOMETRY" > index.csv
declare -a FILES=$(ls -1 *tif);
for FILE in ${FILES[@]}; do
FILE=${FILE%.tif}
echo "$FILE.tif;" > $FILE.txt
gdal_trace_outline $FILE.tif -ndv '0 0' -out-cs en -wkt-out $FILE.wkt
cat $FILE.wkt >> $FILE.txt
cat $FILE.txt >> img_geoms.csv
rm $FILE.wkt $FILE.txt
done
cat img_geoms.csv | perl -i -pe 's~;\n~;~smg' >> index.csv
rm img_geoms.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment