Tuesday, 9 October 2018

Gdal: How to get a pixel's value from raster image?


Given a topographic raster image.



Given a pixel's coordinate in pixel/lines or geocoordinate.


How to get it's pixel value ?



Answer



1. Get the pixels value: gdal's gdallocationinfo allow to access a pixel's value.



The gdallocationinfo utility provide a mechanism to query information about a pixel given it's location in one of a variety of coordinate systems. Several reporting options are provided.



$ gdallocationinfo crop.tif 50 50
Report:
Location: (50px,50line)

Band 1:
Value: 73

To only get the value :


$ gdallocationinfo crop.tif 50 50 -valonly
> 73

Depending on geocoordinate:


$ gdallocationinfo crop.tif -geoloc 0.00 44.00
> 132


Afterwhat you may want to 1. iterate all pixels and 2. apply conditional filter.


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