Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
add comment

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

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
add comment

Your Answer

 
discard

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.