Gdal: How to conditionally assign a new value to the pixels of a bitmap image?

Given the topographic GIS raster of one country crop.tif :

 # 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 

Given the height threshold n = 50 (meters)

How to set the value of all pixels, where z> = n - 50?


Associated with: https://stackoverflow.com/questions/18300210/ , Gdal: how to get the pixel value from a bitmap?

Help ?: gdallocationinfo can get the value of one point (without repeating the entire image):

 $ gdallocationinfo crop.tif 1 1 -valonly > 73 
+4
source share
1 answer

Use gdal_calc.py . Example:

 gdal_calc.py -A crop.tif --outfile=level0100.tif --calc="100*(A>100)" --NoDataValue=0 

read as: `taking into account the input -A (crop.tif), with the output level 0100.tif, when the pixel has the value of the first strip A> 100, the value is set to 100. Else is set to 0.

Inside --calc="" you can set other conditions. If you want to set values ​​like 100 <v <200 to 100, then:

 gdal_calc.py -A crop.tif --outfile=level0100.tif --calc="100*(100<A<200)" --NoDataValue=0 

must work. (this last one has not been tested)

+6
source

Source: https://habr.com/ru/post/1497801/


All Articles