I am using GDAL to "Grow" areas form starting seed points. I have a text file listng the coordinates of my seed locations. The X,Y coordinates are in the coordinate system of a raster image. I want to burn these point locations into the raster image. I don't kow how to convert my point coordinates to the proper raster image pixel/line locations. I have the geotransformation of the image.

I see GDAL classes in the API tutorial that return transformed coordinates from image row/col locations but not the reverse. I am famialiar with the utility that does this, but I don't see a C++ programmers API to do this. Does anyone know how to do this? This capability is fundamental to what I'm trying to do.

Thanks in advance for any help you can offer.

1 Answer 1


This should work (being 'adfGeoTransform' the normal geotransform array and 'adfInvGeoTransform' an empty array of 6 elements to store the inverse geotransform parameters):

GDALInvGeoTransform( adfGeoTransform, adfInvGeoTransform );

iPixel = (int) floor(adfInvGeoTransform[0] 
                 + adfInvGeoTransform[1] * dfGeoX
                 + adfInvGeoTransform[2] * dfGeoY );

iLine = (int) floor(adfInvGeoTransform[3] 
                 + adfInvGeoTransform[4] * dfGeoX
                 + adfInvGeoTransform[5] * dfGeoY );

Don't forget to include gdal.h

  • Just stumbled across this again: I forgot to say Thanks for this. Nov 29, 2012 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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