<div dir="ltr">Please disregard I found what I needed to know in here:<div><a href="http://www.gdal.org/warptut.html">http://www.gdal.org/warptut.html</a><br></div><div><br></div><div style>and in here:</div><div style><a href="http://trac.osgeo.org/gdal/browser/trunk/gdal/alg/gdalwarper.cpp">http://trac.osgeo.org/gdal/browser/trunk/gdal/alg/gdalwarper.cpp</a><br>
</div><div style><br></div><div style>and I now have it coming out correctly tilted.</div><div style><br></div><div style>Thank You,</div><div style>Andy Canfield</div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Mon, Mar 25, 2013 at 5:51 PM, Andy Canfield <span dir="ltr"><<a href="mailto:andy.canfield@gmail.com" target="_blank">andy.canfield@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>I am attempting to tranform a GeoTiff from UTM14N to WGS84 using GDAL from VC++ 2008 and I am brand new to using GDAL.</div><div><br></div><div>When I do the transformation everything seems to go off correctly but when I compare my transformed image in Quantum GIS to the source image projected on the fly by Quantum GIS their image is slightly rotated and mine is straight. Theirs is correct, mine is not(I believe), yet I am not sure what I am doing incorrectly. Is it my affine translation parameters, is it that I am warping it improperly, did I calculate corners improperly or something else entirely?</div>

<div><br></div><div>The source image is a 3 band GeoTiff if that helps at all. </div><div><br></div><div>Here is my complete code as I have it right now:</div><div><br></div><div>#include "stdafx.h"</div><div>#include "gdalwarper.h"</div>

<div>#include "cpl_conv.h"</div><div>#include "gdal_priv.h"</div><div>#include <ogr_spatialref.h></div><div>#include "ogr_srs_api.h"</div><div><br></div><div>int _tmain(int argc, _TCHAR* argv[])</div>

<div>{</div><div><span style="white-space:pre-wrap">  </span>GDALAllRegister();</div><div><br></div><div><span style="white-space:pre-wrap">      </span>GDALDataset  *poDataset, *poDstDS;</div><div><span style="white-space:pre-wrap">       </span>const char *pszFormat = "GTiff";</div>

<div><span style="white-space:pre-wrap">  </span>const char *pszSrcFilename = "C:\\Example\\SampleData\\In.tif";</div><div><span style="white-space:pre-wrap">        </span>const char *pszDstFilename = "C:\\Example\\SampleData\\Out.tif";</div>

<div><span style="white-space:pre-wrap">  </span>GDALDriver *poDriver;</div><div><span style="white-space:pre-wrap">    </span>int rasterCount;</div><div><br></div><div><span style="white-space:pre-wrap">        </span>OGRSpatialReference oSrcSRS,oDstSRS;</div>

<div><span style="white-space:pre-wrap">  </span>char *pszSrcSRSWKT = NULL;</div><div><span style="white-space:pre-wrap">       </span>char *pszDstSRSWKT = NULL;</div><div><br></div><div><span style="white-space:pre-wrap">      </span>OGRCoordinateTransformation *transform = NULL;</div>

<div><br></div><div><span style="white-space:pre-wrap"> </span>double adfSrcGeoTransform[6];</div><div><span style="white-space:pre-wrap">    </span>double adfDstGeoTransform[6];</div><div><span style="white-space:pre-wrap">    </span>double xS[2];</div>

<div><span style="white-space:pre-wrap">  </span>double yS[2];</div><div><br></div><div><span style="white-space:pre-wrap">   </span>//Set destination spatial reference to WGS84 and get its WKT</div><div><span style="white-space:pre-wrap">     </span>oDstSRS.SetWellKnownGeogCS("WGS84");</div>

<div><span style="white-space:pre-wrap">  </span>oDstSRS.exportToWkt(&pszDstSRSWKT);</div><div><br></div><div><span style="white-space:pre-wrap"> </span>//Now set the source spatial reference to UTM14N WGS84 and get its WKT</div>

<div><span style="white-space:pre-wrap">  </span>oSrcSRS.SetProjCS( "UTM 14 (WGS84) in northern hemisphere." );</div><div>    <span style="white-space:pre-wrap">     </span>oSrcSRS.SetWellKnownGeogCS( "WGS84" );</div>

<div>    <span style="white-space:pre-wrap">      </span>oSrcSRS.SetUTM( 14, TRUE );</div><div><span style="white-space:pre-wrap">      </span>oSrcSRS.exportToWkt(&pszSrcSRSWKT);</div><div><br></div><div><span style="white-space:pre-wrap"> </span>//Set the coordinate transformation</div>

<div><span style="white-space:pre-wrap">  </span>transform = OGRCreateCoordinateTransformation(&oSrcSRS,&oDstSRS);</div><div><br></div><div><span style="white-space:pre-wrap">       </span>//Set the GeoTiff driver</div>

<div><span style="white-space:pre-wrap">  </span>poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat);</div><div><br></div><div><span style="white-space:pre-wrap">       </span>// Open input and output files. </div>

<div>    <span style="white-space:pre-wrap">      </span>poDataset = (GDALDataset *) GDALOpen( pszSrcFilename, GA_ReadOnly );</div><div>    <span style="white-space:pre-wrap"> </span>rasterCount = poDataset->GetRasterCount();</div>

<div><br></div><div><span style="white-space:pre-wrap"> </span>poDstDS = poDriver->CreateCopy( pszDstFilename, poDataset, FALSE, NULL, NULL, NULL );</div><div><br></div><div><span style="white-space:pre-wrap">        </span></div>

<div>    <span style="white-space:pre-wrap">      </span>// Setup warp options. </div><div><span style="white-space:pre-wrap">  </span>GDALWarpOptions *psWarpOptions = GDALCreateWarpOptions();</div><div><br></div><div><span style="white-space:pre-wrap">       </span>psWarpOptions->hSrcDS = poDataset;</div>

<div><span style="white-space:pre-wrap">  </span>psWarpOptions->hDstDS = poDstDS;</div><div><br></div><div><br></div><div><span style="white-space:pre-wrap">    </span>psWarpOptions->nBandCount = rasterCount;</div>
<div><span style="white-space:pre-wrap">  </span>psWarpOptions->panSrcBands = (int *) CPLMalloc(sizeof(int) * psWarpOptions->nBandCount );</div><div><span style="white-space:pre-wrap">  </span>psWarpOptions->panDstBands = (int *) CPLMalloc(sizeof(int) * psWarpOptions->nBandCount );</div>

<div><br></div><div><span style="white-space:pre-wrap"> </span>for(int i=0;i<rasterCount;i++)</div><div><span style="white-space:pre-wrap">        </span>{</div><div><span style="white-space:pre-wrap">                </span>psWarpOptions->panSrcBands[i] = i+1;//src band number</div>

<div><span style="white-space:pre-wrap">          </span>psWarpOptions->panDstBands[i] = i+1;//dst band number</div><div><span style="white-space:pre-wrap"> </span>}</div><div><br></div><div><span style="white-space:pre-wrap">       </span>psWarpOptions->pfnProgress = GDALTermProgress;   </div>

<div><br></div><div><span style="white-space:pre-wrap"> </span>// Establish reprojection transformer. </div><div><br></div><div><span style="white-space:pre-wrap"> </span>psWarpOptions->pTransformerArg = </div>
<div><span style="white-space:pre-wrap">          </span>GDALCreateGenImgProjTransformer( poDataset, </div><div><span style="white-space:pre-wrap">                                             </span>pszSrcSRSWKT, </div><div><span style="white-space:pre-wrap">                                           </span>poDstDS,</div>

<div><span style="white-space:pre-wrap">                                          </span>pszDstSRSWKT, </div><div><span style="white-space:pre-wrap">                                           </span>FALSE, 0.0, 1 );</div><div><br></div><div><span style="white-space:pre-wrap">        </span>psWarpOptions->pfnTransformer = GDALGenImgProjTransform;</div>

<div><span style="white-space:pre-wrap">  </span>psWarpOptions->eResampleAlg = GRA_Cubic;</div><div><br></div><div><span style="white-space:pre-wrap">     </span>// Initialize and execute the warp operation. </div><div>
<span style="white-space:pre-wrap">     </span>GDALWarpOperation oOperation;</div><div><br></div><div><span style="white-space:pre-wrap">   </span>oOperation.Initialize( psWarpOptions );</div><div><span style="white-space:pre-wrap">  </span>oOperation.ChunkAndWarpImage( 0, 0, GDALGetRasterXSize( poDstDS ), GDALGetRasterYSize( poDstDS ) );</div>

<div><br></div><div><span style="white-space:pre-wrap"> </span>GDALDestroyGenImgProjTransformer( psWarpOptions->pTransformerArg );</div><div><span style="white-space:pre-wrap">   </span>GDALDestroyWarpOptions( psWarpOptions );</div>

<div><span style="white-space:pre-wrap">  </span></div><div><br></div><div><span style="white-space:pre-wrap">        </span>//Set the new image's projection tag info </div><div><span style="white-space:pre-wrap">   </span>poDstDS->SetProjection(pszDstSRSWKT);</div>

<div><br></div><div><span style="white-space:pre-wrap"> </span>//Get the original affine parameters</div><div><span style="white-space:pre-wrap">     </span>poDataset->GetGeoTransform(adfSrcGeoTransform);</div><div>
<br></div><div><span style="white-space:pre-wrap">    </span>double srcWidth = poDataset->GetRasterXSize();</div><div><span style="white-space:pre-wrap">        </span>double srcHeight = poDataset->GetRasterYSize();</div>
<div><br></div><div><br></div><div><span style="white-space:pre-wrap">        </span>//Get the corners</div><div><span style="white-space:pre-wrap">        </span>xS[0] = adfSrcGeoTransform[0];//minx</div><div><span style="white-space:pre-wrap">     </span>xS[1] = adfSrcGeoTransform[0] + srcWidth*adfSrcGeoTransform[1] + srcHeight*adfSrcGeoTransform[2];//??? maxx </div>

<div><span style="white-space:pre-wrap">  </span> </div><div><span style="white-space:pre-wrap">        </span>yS[0] = adfSrcGeoTransform[3];//maxy</div><div><span style="white-space:pre-wrap">     </span>yS[1] = adfSrcGeoTransform[3] + srcWidth*adfSrcGeoTransform[4] + srcHeight*adfSrcGeoTransform[5];//??? miny</div>

<div><br></div><div><br></div><div><span style="white-space:pre-wrap">        </span>//Reproject its corners coordinate info</div><div><span style="white-space:pre-wrap">  </span>transform->Transform(2,xS,yS);</div><div>
<br></div><div><span style="white-space:pre-wrap">    </span>//Set all the new affine parameters</div><div><span style="white-space:pre-wrap">      </span>adfDstGeoTransform[0] = xS[0];</div><div><span style="white-space:pre-wrap">   </span>adfDstGeoTransform[1] = (xS[1] - xS[0]) / srcWidth;//(xMax - xMin) / imageWidth </div>

<div><span style="white-space:pre-wrap">  </span>adfDstGeoTransform[2] = adfSrcGeoTransform[2];</div><div><span style="white-space:pre-wrap">   </span>adfDstGeoTransform[3] = yS[0];</div><div><span style="white-space:pre-wrap">   </span>adfDstGeoTransform[4] = adfSrcGeoTransform[4];</div>

<div><span style="white-space:pre-wrap">  </span>adfDstGeoTransform[5] = ((yS[0] - yS[1]) / srcHeight)*(-1);//((yMax - yMin) / imageHeight)*(-1) </div><div><br></div><div><span style="white-space:pre-wrap">        </span>//Set the new images affine information</div>

<div><span style="white-space:pre-wrap">  </span>poDstDS->SetGeoTransform(adfDstGeoTransform);</div><div><br></div><div>    <span style="white-space:pre-wrap">    </span>GDALClose( poDstDS );</div><div>    <span style="white-space:pre-wrap">        </span>GDALClose( poDataset );</div>

<div><br></div><div>    <span style="white-space:pre-wrap">     </span>return 0;</div><div>}</div><div><br></div><div>Thank you in advance for any help you folks may be able to give me on this.</div><span class="HOEnZb"><font color="#888888"><div>
<br></div>
<div>-Andy</div></font></span></div>
</blockquote></div><br></div></div>