I have a simple GeoTIFF file where I want to query the pixel value of a certain geocoordinate. I have no experience in this topic and there nearly no tutorials or whatever about this topic.

All I know is, it's clearly possible... but where to start? I need to do this in C# because my whole environment is based on it.

Are there any examples?

  • 1
    It's just math, right? Using the extent, figure which row,column the point lands in, then read the pixel. We have a policy here that coding questions must contain code. You still need to choose an API and work with that to retrieve the extent.
    – Vince
    May 18 at 15:55
  • @Vince Oh that actually sounds much simpler. May i ask how that math looks like ? I actually have no real experience in that topic, so im sorry for my stupidity.
    – genaray
    May 18 at 15:57

1 Answer 1

  1. First inspect the EXIF tags of geoTiff file using gdal info <geotiff_file> and get the coordinates of the corners of your GeoTiff. In case you want to do this programatically read this thread How to get raster corner coordinates using Python GDAL bindings?

  2. Corners Coordinates can be in a different CRS so check for the EPSG code and if required convert the coordinates of the corners of GeoTiff to a meter based coordinate projection. For eg. any UTM (Universal Transverse Mercator) based projection is meter based. Doing this will make your calculations more easier.

  3. Since you know shape/dimension of the image find meters per pixel by finding difference between 2 corners of the sides of the image. If the image is not square, you will have to find meters per pixel width wise and height wise.

Let's take and example of image below, where the image is square find 2 corners of any of the sides for eg. assume the corner MinX, MaxY = (0,1000) and MaxX, MaxY = (1000,1000) are the coordinnates in meters and the dimension of the image is 100x100 then meters per pixel is (1000-0)/100 = 10 meters/pixel

enter image description here

Once you arrive at this value your calculations are simple, given a pixel find out where it is located with respect to the corner and multiply it by meters per pixel value to get the coordinate. For eg. in the above example we calculated the value of meters per pixel to be 10 so the pixel (5,50) should have coordinates (5x10, 50x10)=(50,500).

Not the answer you're looking for? Browse other questions tagged or ask your own question.