1

I would like to know if it is possible to calculate the geographic coordinates (lat, lon) for a pixel specified by its x/y (top-left) cartesian coordinates in a map image/raster?

The datum and projection are known: WSG84/EPSG4326 , as the envelope/extent (4 "corners" + the center point).

It seems the goal is somewhat similar to the one of gdallocationinfo, but I don't find the way to indicate the map extent/bbox.

If possible, tools from GDAL or GeographicLib can be used.

I can't find the related formula.

2

What you need is affine transformation and it should be easy to do with Python:

You'll need GDAL GeoTransform (and it seems like you have all you need for it):

gt[0] /* top left x */
gt[1] /* w-e pixel resolution */
gt[2] /* 0 */
gt[3] /* top left y */
gt[4] /* 0 */
gt[5] /* n-s pixel resolution (negative value) */

And then having your x,y:

geo_x = gt[0] + (x+0.5) * gt[1] + (y+0.5) * gt[2]
geo_y = gt[3] + (x+0.5) * gt[4] + (y+0.5) * gt[5]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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