<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7652.24">
<TITLE>Help understanding GDALApplyGeoTransform and GDALInvGeoTransform</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">Hi All,</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">I found a post a while back regarding GDALApplyGeoTransform</FONT></SPAN><SPAN LANG="en-us"> <FONT FACE="OCR A Extended">and GDALInvGeoTransform</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">(</FONT></SPAN><SPAN LANG="en-us"></SPAN><A HREF="http://n2.nabble.com/Converting-raster-pixel-space-to-geospace-td3258751.html"><SPAN LANG="en-us"><U><FONT COLOR="#0000FF" FACE="OCR A Extended">http://n2.nabble.com/Converting-raster-pixel-space-to-geospace-td3258751.html</FONT></U></SPAN><SPAN LANG="en-us"></SPAN></A><SPAN LANG="en-us"><FONT FACE="OCR A Extended"> )</FONT></SPAN><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><B></B></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">GDALApplyGeoTransform</FONT></SPAN><SPAN LANG="en-us"><FONT FACE="OCR A Extended">() will convert from pixels to georeferenced positions</FONT></SPAN><SPAN LANG="en-us"><BR>
<FONT FACE="OCR A Extended">and GDALInvGeoTransform() will invert the geotransform matrix, so using</FONT></SPAN><SPAN LANG="en-us"><BR>
<FONT FACE="OCR A Extended">GDALApplyGeoTransform</FONT></SPAN><SPAN LANG="en-us"><FONT FACE="OCR A Extended">() on that inverted matrix will do the reverse</FONT></SPAN><SPAN LANG="en-us"><BR>
<FONT FACE="OCR A Extended">conversion (georeferenced positions --> pixel positions)</FONT></SPAN><SPAN LANG="en-us"></SPAN></P>
<BR>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">I have</FONT></SPAN><SPAN LANG="en-us"> <FONT FACE="OCR A Extended">written</FONT></SPAN><SPAN LANG="en-us"><FONT FACE="OCR A Extended"> some test code that for some reason is not returning the correct results:</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">double adfGeoTransform[6] = { -127, .011571482, 0, 51, 0, -.008993 };</FONT></SPAN><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">double adfReverseGeoTransform[6] = { 0, 0, 0, 0, 0, 0 };</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">GDALInvGeoTransform( adfGeoTransform, adfReverseGeoTransform );</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">double dfPixel = 0;</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">double dfLine = 0;</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">double x;</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">double y;</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">GDALApplyGeoTransform( adfGeoTransform, dfPixel, dfLine, &x, &y );</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">s</FONT></SPAN><SPAN LANG="en-us"><FONT FACE="OCR A Extended">td::cout << "lat-lon " << x << ", " << y << std::endl;</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">double new_x;</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">double new_y;</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">G</FONT></SPAN><SPAN LANG="en-us"><FONT FACE="OCR A Extended">DALApplyGeoTransform( adfReverseGeoTransform,</FONT></SPAN><SPAN LANG="en-us"> <FONT FACE="OCR A Extended">x</FONT></SPAN><SPAN LANG="en-us"><FONT FACE="OCR A Extended">,</FONT></SPAN><SPAN LANG="en-us"> <FONT FACE="OCR A Extended">y</FONT></SPAN><SPAN LANG="en-us"><FONT FACE="OCR A Extended">, &new_x, &new_y );</FONT></SPAN><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">std::cout << new_x << ", " << new_y << std::endl;</FONT></SPAN><SPAN LANG="en-us"></SPAN></P>
<BR>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">====================================================================================</FONT></SPAN><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><B><FONT FACE="OCR A Extended">Output</FONT></B></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><B><FONT FACE="OCR A Extended">lat-lon -127, 51</FONT></B></SPAN><SPAN LANG="en-us"><B><FONT FACE="OCR A Extended"> This result is correct as I have requested the lat-lon of the first point.</FONT></B></SPAN><SPAN LANG="en-us"><B></B></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">This result is NOT correct. I pushed the</FONT></SPAN><SPAN LANG="en-us"> <FONT FACE="OCR A Extended">values -127, and 51 through the inverse transform. I would have thought the answer</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">Would have been 0, 0. </FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><B><FONT FACE="OCR A Extended">10975.3, 5671.08</FONT></B></SPAN><SPAN LANG="en-us"><B></B></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">Thanks,</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="OCR A Extended">Bill</FONT></SPAN><SPAN LANG="en-us"></SPAN></P>
</BODY>
</HTML>