GDAL – How to Get a Pixel’s Value from Raster Image Using GDAL

gdalrastertopography

Given a topographic raster image.

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

How to get it's pixel value ?

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