Monday, 8 May 2017

Gdal: how to get the max and min altitudes of my topographic raster?


Given a .tiff topographic raster image.


How to get the altitudes of the highest and lowest point/pixel ?



Answer



You can use :


gdalinfo -mm input.tif


It returns a range of infos within which is the string Computed Min/Max=-425.000,8771.000, for my Eurasian raster.


Some cleanup and you get your vertical min/max variables:


$zMin=`gdalinfo -mm ./input.tif | sed -ne 's/.*Computed Min\/Max=//p'| tr -d ' ' | cut -d "," -f 1 | cut -d . -f 1`
$zMax=`gdalinfo -mm ./input.tif | sed -ne 's/.*Computed Min\/Max=//p'| tr -d ' ' | cut -d "," -f 2 | cut -d . -f 1`
$echo $zMin $zMax
>-425 8771

I trimed both the digits after decimal point and the spaces in case via cut -d -f and tr -d ' ', respectively. Adapt as needed.


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...