[gdal-dev] Help understanding GDALApplyGeoTransform and GDALInvGeoTransform

Cassanova, Bill BCassanova at weather.com
Fri Jul 31 13:56:39 EDT 2009


Hi All,

I found a post a while back regarding GDALApplyGeoTransform and
GDALInvGeoTransform
(http://n2.nabble.com/Converting-raster-pixel-space-to-geospace-td325875
1.html )

GDALApplyGeoTransform() will convert from pixels to georeferenced
positions 
and GDALInvGeoTransform() will invert the geotransform matrix, so using 
GDALApplyGeoTransform() on that inverted matrix will do the reverse 
conversion (georeferenced positions --> pixel positions)


I have written some test code that for some reason is not returning the
correct results:

double adfGeoTransform[6] = { -127, .011571482, 0, 51, 0, -.008993 };

double adfReverseGeoTransform[6] = { 0, 0, 0, 0, 0, 0 };

GDALInvGeoTransform( adfGeoTransform, adfReverseGeoTransform );

double dfPixel = 0;
double dfLine = 0;
double x;
double y;

GDALApplyGeoTransform(   adfGeoTransform, dfPixel, dfLine, &x, &y );

std::cout << "lat-lon " << x << ", " << y << std::endl;

double new_x;
double new_y;

GDALApplyGeoTransform(   adfReverseGeoTransform, x, y, &new_x, &new_y );

std::cout << new_x << ", " << new_y << std::endl;


========================================================================
============
Output

lat-lon -127, 51  This result is correct as I have requested the lat-lon
of the first point.

This result is NOT correct.  I pushed the values -127, and 51 through
the inverse transform.  I would have thought the answer
Would have been 0, 0.  

10975.3, 5671.08

Thanks,
Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20090731/c85114b8/attachment.html


More information about the gdal-dev mailing list