<html><div style='background-color:'><DIV class=RTE>Hello,</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I have a problem with my reprojection example program, I am new to GDAL and still getting familiar with the&nbsp;its functionality. A couple of days back I could not get the program output a coloured image, but it turned out that I should have set INTERLEAVE=PIXEL, thanks to Frank I fixed that part. I thought that the reprojection occured and the output image was no different from input because the transition between NAD83 to WGS84 causes almost no distortion on larger scale. Today, however, I wanted to verify this by using OpenEV tool written, as I understand, in Python. I took my source image file, which is NAD83, then I took another proper&nbsp;geotiff which is in WGS84 and extracted the projection information from it to use in my transformation, here are the input and output WKTs:</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>INPUT:</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>PROJCS["NAD83 / UTM zone 17N",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.2572221010002,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4269"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-81],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","26917"]]</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>OUTPUT:</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.2572235630016,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]]</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I used the above in the Compose Dataset function in OpenEV and using the geotransform reprojection I converted the original geotiff from NAD83 to WGS84, the result came out to be what I expected from the beginning, which is a slightly rotated image and slightly squished from top to bottom. I do not know how OpenEV uses GDAL to make the correct transformation, but in my case it does not work. If someone can help me I would really appreciate it. Thank you very much ahead. I pasted the code below. I could make screenshots if that would help.</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ilya.</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>P.S. The following is the code of my button click on a dialog form in vc++ 6, very simple:</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>void CTest01Dlg::OnButtonProcess() <BR>{<BR>&nbsp;// ------------ Example of initializing an image into the GDALDataset object<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; GDALDataset&nbsp; *poDataset;</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; // -------------- Reprojection example</DIV>
<DIV class=RTE>&nbsp;GDALDatasetH&nbsp; hSrcDS, hDstDS, hRefDS;</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; // Open input file. </DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; GDALAllRegister();</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; hSrcDS = GDALOpen( fileNameIn, GA_ReadOnly );</DIV>
<DIV class=RTE>// Open the reference file, from which projection WKT would be used for output file.<BR>&nbsp;hRefDS = GDALOpen( fileNameRef, GA_ReadOnly );</DIV>
<DIV class=RTE><BR>&nbsp;//AfxMessageBox(str.Format("%d\n",hSrcDS-&gt;GetGCPCount()));</DIV>
<DIV class=RTE>&nbsp;poDataset = (GDALDataset *) hSrcDS;<BR>&nbsp;&nbsp;&nbsp; if( poDataset == NULL )<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CTest01Dlg::SendDlgItemMessage(IDC_LIST_STATUS, LB_ADDSTRING, 0, (LPARAM)strcat("The input file does not exist: ", fileNameIn));<BR>&nbsp;&nbsp;exit(1);<BR>&nbsp;&nbsp;&nbsp; }</DIV>
<DIV class=RTE>&nbsp;GDALDriverH hDriver;<BR>&nbsp;&nbsp;&nbsp; GDALDataType eDT;</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; // Open the source file. </DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; CPLAssert( hSrcDS != NULL );<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; // Create output with same datatype as first input band. </DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; eDT = GDALGetRasterDataType(GDALGetRasterBand(hSrcDS,1));</DIV>
<DIV class=RTE>&nbsp;//CString str;<BR>&nbsp;//str.Format("%d\n",eDT);<BR>&nbsp;//AfxMessageBox(str);</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; // Get output driver (GeoTIFF format)</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; hDriver = GDALGetDriverByName("GTiff");<BR>&nbsp;&nbsp;&nbsp; CPLAssert( hDriver != NULL );</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; // Get Source coordinate system. </DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; const char *pszSrcWKT = NULL;<BR>&nbsp;const char *pszRefWKT = NULL;<BR>&nbsp;char *pszDstWKT;</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; pszSrcWKT = GDALGetProjectionRef( hSrcDS );<BR>&nbsp;&nbsp;&nbsp; CPLAssert( pszSrcWKT != NULL &amp;&amp; strlen(pszSrcWKT) &gt; 0 );<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; pszRefWKT = GDALGetProjectionRef( hRefDS );<BR>&nbsp;&nbsp;&nbsp; CPLAssert( pszRefWKT != NULL &amp;&amp; strlen(pszRefWKT) &gt; 0 );</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; // Setup output coordinate system that is UTM 17 WGS84. </DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; OGRSpatialReference oSRS;</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; //oSRS.SetUTM(17, TRUE);<BR>&nbsp;&nbsp;&nbsp; //oSRS.SetWellKnownGeogCS("WGS84");</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; oSRS.exportToWkt( &amp;pszDstWKT );</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; // Create a transformer that maps from source pixel/line coordinates<BR>&nbsp;&nbsp;&nbsp; // to destination georeferenced coordinates (not destination <BR>&nbsp;&nbsp;&nbsp; // pixel line).&nbsp; We do that by omitting the destination dataset<BR>&nbsp;&nbsp;&nbsp; // handle (setting it to NULL). </DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; void *hTransformArg;</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; hTransformArg = GDALCreateGenImgProjTransformer( hSrcDS, pszSrcWKT, NULL, pszRefWKT, FALSE, 0, 1 );<BR>&nbsp;&nbsp;&nbsp; CPLAssert( hTransformArg != NULL );</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; // Get approximate output georeferenced bounds and resolution for file. </DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; double adfDstGeoTransform[6];<BR>&nbsp;&nbsp;&nbsp; int nPixels = 0, nLines = 0;<BR>&nbsp;&nbsp;&nbsp; CPLErr eErr;</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; eErr = GDALSuggestedWarpOutput( hSrcDS, GDALGenImgProjTransform, hTransformArg, adfDstGeoTransform, &amp;nPixels, &amp;nLines );<BR>&nbsp;&nbsp;&nbsp; CPLAssert( eErr == CE_None );</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; GDALDestroyGenImgProjTransformer( hTransformArg );</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; // Create the output file.<BR>&nbsp;char *apszOptions[] = {"INTERLEAVE=PIXEL", NULL};<BR>&nbsp;hDstDS = GDALCreate(hDriver, fileNameOut, nPixels, nLines, GDALGetRasterCount(hSrcDS), eDT, apszOptions);<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; CPLAssert( hDstDS != NULL );</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; // Write out the projection definition. </DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; GDALSetProjection(hDstDS, pszRefWKT);<BR>&nbsp;&nbsp;&nbsp; GDALSetGeoTransform(hDstDS, adfDstGeoTransform);</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; // Copy the color table, if required.</DIV>
<DIV class=RTE>&nbsp;// --------------- For debugging-----------------------<BR>&nbsp;//str.Format("DEBUG INFO: %d\n",GDALGetRasterCount(hDstDS));<BR>&nbsp;//AfxMessageBox(str);<BR>&nbsp;// ----------------------------------------------------</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; GDALColorTableH hCT;</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; hCT = GDALGetRasterColorTable(GDALGetRasterBand(hSrcDS,1));<BR>&nbsp;GDALSetRasterColorTable(GDALGetRasterBand(hDstDS,1), hCT);</DIV>
<DIV class=RTE>&nbsp;//str.Format("DEBUG INFO: \n %d \n ",GDALGetRasterCount(hDstDS));<BR>&nbsp;//AfxMessageBox(eRBCI.*/<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; hCT = GDALGetRasterColorTable(GDALGetRasterBand(hSrcDS,2));<BR>&nbsp;&nbsp;&nbsp; GDALSetRasterColorTable(GDALGetRasterBand(hDstDS,2), hCT);</DIV>
<DIV class=RTE>&nbsp;<BR>&nbsp;&nbsp;&nbsp; hCT = GDALGetRasterColorTable(GDALGetRasterBand(hSrcDS,3));<BR>&nbsp;&nbsp;&nbsp; GDALSetRasterColorTable(GDALGetRasterBand(hDstDS,3), hCT);</DIV>
<DIV class=RTE><BR>&nbsp;CTest01Dlg::SendDlgItemMessage(IDC_LIST_STATUS, LB_ADDSTRING, 0, (LPARAM)"Setup warp options ...");</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; // Setup warp options. </DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; GDALWarpOptions *psWarpOptions = GDALCreateWarpOptions();</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; psWarpOptions-&gt;hSrcDS = hSrcDS;<BR>&nbsp;&nbsp;&nbsp; psWarpOptions-&gt;hDstDS = hDstDS;<BR>&nbsp;&nbsp;&nbsp; psWarpOptions-&gt;nBandCount = 3;<BR>&nbsp;&nbsp;&nbsp; psWarpOptions-&gt;panSrcBands = (int *) CPLMalloc(sizeof(int) * psWarpOptions-&gt;nBandCount);<BR>&nbsp;&nbsp;&nbsp; psWarpOptions-&gt;panSrcBands[0] = 1;<BR>&nbsp;&nbsp;&nbsp; psWarpOptions-&gt;panSrcBands[1] = 2;<BR>&nbsp;&nbsp;&nbsp; psWarpOptions-&gt;panSrcBands[2] = 3;<BR>&nbsp;&nbsp;&nbsp; psWarpOptions-&gt;panDstBands = (int *) CPLMalloc(sizeof(int) * psWarpOptions-&gt;nBandCount);<BR>&nbsp;&nbsp;&nbsp; psWarpOptions-&gt;panDstBands[0] = 1;<BR>&nbsp;psWarpOptions-&gt;panDstBands[1] = 2;<BR>&nbsp;psWarpOptions-&gt;panDstBands[2] = 3;</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; psWarpOptions-&gt;pfnProgress = GDALTermProgress;<BR>&nbsp;<BR>&nbsp;CTest01Dlg::SendDlgItemMessage(IDC_LIST_STATUS, LB_ADDSTRING, 0, (LPARAM)"Establishing transformer ...");</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; // Establish reprojection transformer. </DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; psWarpOptions-&gt;pTransformerArg = GDALCreateGenImgProjTransformer(hSrcDS, GDALGetProjectionRef(hSrcDS), hDstDS, GDALGetProjectionRef(hDstDS), FALSE, 0.0, 1);<BR>&nbsp;&nbsp;&nbsp; psWarpOptions-&gt;pfnTransformer = GDALGenImgProjTransform;</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; // Initialize and execute the warp operation.<BR>&nbsp;<BR>&nbsp;CTest01Dlg::SendDlgItemMessage(IDC_LIST_STATUS, LB_ADDSTRING, 0, (LPARAM)"Executing ...");</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; GDALWarpOperation oOperation;</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp; // Initialize transformation operation<BR>&nbsp;oOperation.Initialize(psWarpOptions);</DIV>
<DIV class=RTE>&nbsp;// Perform the transformation<BR>&nbsp;&nbsp;&nbsp; oOperation.ChunkAndWarpImage(0, 0, GDALGetRasterXSize(hDstDS), GDALGetRasterYSize(hDstDS));</DIV>
<DIV class=RTE>&nbsp;// Clean up the intermediate objects<BR>&nbsp;&nbsp;&nbsp; GDALDestroyGenImgProjTransformer(psWarpOptions-&gt;pTransformerArg);<BR>&nbsp;&nbsp;&nbsp; GDALDestroyWarpOptions(psWarpOptions);</DIV>
<DIV class=RTE>&nbsp;CTest01Dlg::SendDlgItemMessage(IDC_LIST_STATUS, LB_ADDSTRING, 0, (LPARAM)"Done ...");</DIV>
<DIV class=RTE>&nbsp;// Close the input and output files<BR>&nbsp;&nbsp;&nbsp; GDALClose(hDstDS);<BR>&nbsp;&nbsp;&nbsp; GDALClose(hSrcDS);<BR>&nbsp;GDALClose(hRefDS);<BR>}</DIV>
<DIV class=RTE>void CTest01Dlg::OnButtonCleanup() <BR>{<BR>&nbsp;remove(fileNameOut);<BR>&nbsp;CTest01Dlg::SendDlgItemMessage(IDC_LIST_STATUS, LB_ADDSTRING, 0, (LPARAM)"Cleanup complete ...");<BR>}</DIV></div></html>