GDAL Polygonize in Action!

#!/bin/bash
for VARIABLE in ./test_export/*.tif; do
   gdal_translate -of GTiff -a_nodata 0 "$VARIABLE" "PPR_no/$(basename "$VARIABLE" .tif).tif"
   gdal_sieve.py -st 2 -8 "PPR_no/$(basename "$VARIABLE" .tif).tif"
   gdal_polygonize.py -8 "PPR_no/$(basename "$VARIABLE" .tif).tif" -f "ESRI Shapefile" "shapefile/$(basename "$VARIABLE" .tif).shp"
   rm "PPR_no/$(basename "$VARIABLE" .tif).tif"
   ogr2ogr -f "ESRI Shapefile" -progress "shapefiles/$(basename "$VARIABLE" .tif).shp" "shapefile/$(basename "$VARIABLE" .tif).shp" -t_srs "EPSG:5070"
done

listofmodisdays=`ls shapefiles/*.shp | cut -d/ -f2 | cut -d- -f1 | uniq`

for i in $listofmodisdays; do
   file="./final/$i.shp"
   for y in $(ls shapefiles/$i*.shp); do
      if [ -f "$file" ]; then
         ogr2ogr -f "ESRI Shapefile" -update -append $file $y -nln $i
      else
         ogr2ogr -f "ESRI Shapefile" $file $y
      fi
   done
done

Leave a Reply

Your email address will not be published. Required fields are marked *