[gdal-dev] help about the GDAL efficiency

xialang2012 xialang2012 at 163.com
Tue May 19 17:18:23 PDT 2015


Hi, 

I used GDAL to reproject the TM images, and the original projection of the TM images was longitude/latitude WGS84, the final projection was UTM 51. The codes I used is as following:

void doCore()
{

 GDALDataType eDT;
 GDALDataset *hDstDS;
 GDALDataset *hSrcDS;

 GDALAllRegister();

 //  cache Max
 GDALSetCacheMax(1024*1024*1024);

 // open file
 hSrcDS = (GDALDataset *)GDALOpen( "G:\\Data\\TM\\0_Water_Vapor_Near_Infrared.tif", GA_ReadOnly );
 CPLAssert( hSrcDS != NULL );

 GDALRasterBand *iBand1 = hSrcDS->GetRasterBand(1); 

 const char *pszSrcWKT;
 char *pszDstWKT = NULL;
 pszSrcWKT = GDALGetProjectionRef( hSrcDS );
 CPLAssert( pszSrcWKT != NULL && strlen(pszSrcWKT) > 0 );


    // set UTM
 OGRSpatialReference oSRS;
 oSRS.SetUTM(51, TRUE);
 oSRS.SetWellKnownGeogCS("WGS84");
 oSRS.exportToWkt( &pszDstWKT );

 void *hTransformArg;
 hTransformArg = GDALCreateGenImgProjTransformer( hSrcDS, pszSrcWKT, NULL, pszDstWKT, FALSE, 0, 1 );
 CPLAssert( hTransformArg != NULL );

 // calculate 6 parameters 
 double adfDstGeoTransform[6];
 int nPixels=0, nLines=0;
 CPLErr eErr;
 eErr = GDALSuggestedWarpOutput( hSrcDS, GDALGenImgProjTransform, hTransformArg, adfDstGeoTransform, &nPixels, &nLines );
 CPLAssert( eErr == CE_None );
 GDALDestroyGenImgProjTransformer(hTransformArg);


 // create out file
 eDT = GDALDataType(iBand1->GetRasterDataType());
 GDALDriver *hDriver = (GDALDriver *)GDALGetDriverByName( "GTiff" );
 CPLAssert( hDriver != NULL );
 hDstDS = (GDALDataset *)GDALCreate( hDriver, "G:\\data\\TM\\out.tif", nPixels, nLines, GDALGetRasterCount(hSrcDS), eDT, NULL );
 CPLAssert( hDstDS != NULL );

 // write projection info
 hDstDS->SetProjection(pszDstWKT);
 hDstDS->SetGeoTransform(adfDstGeoTransform);

 // create warp info 
 GDALWarpOptions *psWarpOptions = GDALCreateWarpOptions();

 psWarpOptions->dfWarpMemoryLimit = 1024*1024*1024;
 psWarpOptions->hSrcDS = hSrcDS;
 psWarpOptions->hDstDS = hDstDS;

 psWarpOptions->nBandCount = 1;
 psWarpOptions->panSrcBands = (int *) CPLMalloc(sizeof(int) );
 psWarpOptions->panSrcBands[0] = 1;
 psWarpOptions->panDstBands = (int *) CPLMalloc(sizeof(int) );
 psWarpOptions->panDstBands[0] = 1;

 psWarpOptions->pfnProgress = GDALTermProgress;

 psWarpOptions->pTransformerArg = GDALCreateGenImgProjTransformer( hSrcDS, pszSrcWKT, hDstDS, pszDstWKT, FALSE, 0, 1 );
 psWarpOptions->pfnTransformer = GDALGenImgProjTransform;

 // do it 
 GDALWarpOperation oOPeration;
 oOPeration.Initialize(psWarpOptions);
 oOPeration.ChunkAndWarpMulti(0, 0, nPixels, nLines);

 GDALDestroyGenImgProjTransformer(psWarpOptions->pTransformerArg);
 GDALDestroyWarpOptions( psWarpOptions );
 CPLFree(pszDstWKT);

 GDALClose(hDstDS);
 GDALClose(hSrcDS);
}

However, the time which the codes spent to process one image is about 70 seconds in VS 2010 x64 release, and in ENVI/IDL, it was only spend 45 seconds. So, I am wonder whether something wrong in my codes? Thanks!

Yours,
Xia Lang


2015-05-18


xialang2012 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20150520/56a5ee34/attachment.html>


More information about the gdal-dev mailing list