[gdal-dev] help about the GDAL efficiency

Even Rouault even.rouault at spatialys.com
Wed May 20 01:31:40 PDT 2015


Xia Lang,

> 
> 
>  // 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 ); 

--> You might consider tiling your output dataset, if that's OK for your use 
(passing TILED=YES as creation optoins)

> CPLAssert(
> hDstDS != NULL );
> 
>  // write projection info
>  hDstDS->SetProjection(pszDstWKT);
>  hDstDS->SetGeoTransform(adfDstGeoTransform);
> 
>  // create warp info
>  GDALWarpOptions *psWarpOptions = GDALCreateWarpOptions();
> 
>  psWarpOptions->dfWarpMemoryLimit = 1024*1024*1024;

--> You likely don't need such a bit value. 60 or 100 MB should be OK.

>  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;

Try adding the following to use an approximate transformer, which is the 
default behaviour of gdalwarp. The computations involved in UTM projection are 
quite heavy and this should help a lot.

/* -------------------------------------------------------------------- */
/*      Warp the transformer with a linear approximator unless the      */
/*      acceptable error is zero.                                       */
/* -------------------------------------------------------------------- */
        double dfErrorThreshold = 0.125;
        {
            psWarpOptions->pTransformerArg =
                GDALCreateApproxTransformer( GDALGenImgProjTransform, 
                                             psWarpOptions->pTransformerArg, 
dfErrorThreshold);
            psWarpOptions->pfnTransformer = GDALApproxTransform;
            GDALApproxTransformerOwnsSubtransformer(psWarpOptions-
>pTransformerArg, TRUE);
        }



> 
>  // 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!

Did you compare with the speed of the pre-built gdalwarp utility ? But I'm 
confident that the approximation transformer might be the key to speed up.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list