Wednesday, 13 September 2017

gdal - Gdal_polygonize: How to filter pixels above a given value (elevation)?


Given a topographic GIS raster of one country:


Given an elevation threshold n = 50 (meters)


How to polygonize pixels when z >= n ?


gdal_polygonize.py is not clear on this point. It states This utility creates vector polygons for all connected regions of pixels in the raster sharing a common pixel value. So I guess it MUST be like z = something and only this. I don't understand where to state the condition.





Current workflow details:


# download:
curl -o ETOPO1.zip 'http://www.ngdc.noaa.gov/mgg/global/relief/ETOPO1/data/ice_surface/grid_registered/georeferenced_tiff/ETOPO1_Ice_g_geotiff.zip'
# unzip:
unzip ETOPO1.zip
# crop:
gdal_translate -projwin -005.50 051.30 10.00 041.00 ETOPO1_Ice_g_geotiff.tif crop.tif

Related to: Topography: How to convert raster into vector layers?, Get a pixel value.




Answer



Given your crop.tif raster layer, you can filter its pixels whose elevation is above the threshold (50 m) using gdal_calc.py:


gdal_calc.py -A crop.tif --outfile=result.tif --calc="A>=50" --NoDataValue=0

The result.tif will be made of 1 where the condition is satisfied, 0 otherwise. Then, it will be possible to vectorize result.tif using gdal_polygonize.py:


gdal_polygonize.py result.tif result.shp

Finally, you can filter only the polygon(s) you need creating a new shapefile:


ogr2ogr filtered_result.shp result.shp -where "Value=1"

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...