Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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

share|improve this answer
Just stumbled across this again: I forgot to say Thanks for this. – Frederick Irani Nov 29 '12 at 18:52
You're welcome :-) – jorgeas80 Dec 7 '12 at 17:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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