[gdal-dev] GDALWarpOperation.ChunkAndWarpImage on source without CRS

Radim Blazek radim.blazek at gmail.com
Wed Mar 9 16:27:19 EST 2011


Hi,
thank you a lot for your help and recommendations.
The problem seems to be in GDALCreateGenImgProjTransformer2 in the
block which begins on line 1072 (alg/gdaltransformer.cpp) current
trunk:

    else if( (pszMethod == NULL || EQUAL(pszMethod,"GEOTRANSFORM"))
             && GDALGetGeoTransform( hSrcDS, psInfo->adfSrcGeoTransform )
             == CE_None
             && (psInfo->adfSrcGeoTransform[0] != 0.0
                 || psInfo->adfSrcGeoTransform[1] != 1.0
                 || psInfo->adfSrcGeoTransform[2] != 0.0
                 || psInfo->adfSrcGeoTransform[3] != 0.0
                 || psInfo->adfSrcGeoTransform[4] != 0.0
                 || ABS(psInfo->adfSrcGeoTransform[5]) != 1.0) )

here it excludes all source data sources which are not georeferenced.
If I comment the psInfo->adfSrcGeoTransform check, everything works
OK. Is there a good reason to not allow to transform images which are
not georeferenced?

I  can get around also setting for example
psInfo->adfSrcGeoTransform[0] = 0.00000001;
in my code, but that is not nice of course. Is there a better workaround?

Radim

On Wed, Mar 9, 2011 at 7:49 PM, Even Rouault
<even.rouault at mines-paris.org> wrote:
> Le mercredi 09 mars 2011 12:25:47, Radim Blazek a écrit :
>
> Radim,
>
> I don't see anything obviously wrong in your code, but the warping API is
> admitedly quite tricky to use. The closest code in GDAL that you could take
> insipiration from is perhaps GDALReprojectImage() in alg/gdalwarper.cpp that
> does pretty similar things to your code (apps/gdalwarp.cpp does similar things
> too but perhaps a bit less clear to follow).
>
> 1) The cause of the crash is the pTransformArg=0x0 passed to
> GDALGenImgProjTransform () which causes a null pointer deferencing when doing
> psInfo->pDstGCPTransformArg. I'm surprised that it crashes here and not the
> line before where the psInfo is already deferenced (is your GDAL build with -
> O2 ? If yes, you should perhaps rebuild it without it). I don't either
> understand how you get a null pointer at that point. I don't either understand
> why the fact that the source dataset has a SRS or not has an impact at that
> point... Stepping in the code with a debugger might help to track where that
> null pointer comes from. (the line numbers didn't match the ones of my copy so
> I suspect you're not using GDAL 1.8.0, but that shouldn't be an issue however)
>
> 2) Yes, indeed pDstGCPTransformArg is unused. So there's perhaps some code
> cleaning possible inside GDAL here, but that's unlikely to cause a problem per
> se.
>
> 3) You should check the return value of myOperation.Initialize( myWarpOptions
> ).
> If the validation of the warp options failed, it would be unsafe to go on with
> the warping itself.
>
> 4) myMemDsn.sprintf(
> "MEM:::DATAPOINTER=%lu,PIXELS=%d,LINES=%d,BANDS=1,DATATYPE=%s,PIXELOFFSET=0,LINEOFFSET=0,BANDOFFSET=0",
> ( long )theBlock, thePixelWidth, thePixelHeight,  GDALGetDataTypeName((
> GDALDataType )mGdalDataType[theBandNo-1] ) );  is dangerous. I think it will
> not work for a Win64 build where pointers are 64 bits but long is still 32
> bit. You could use the CPLPrintPointer() function from GDAL to format it :
>
>    char szPointer[64];
>    memset( szPointer, 0, sizeof(szPointer) );
>    CPLPrintPointer( szPointer, theBlock, sizeof(szPointer) );
>
> Best regards,
>
> Even
>
>
>> Hi,
>> I am using GDALWarpOperation.ChunkAndWarpImage to read data,
>> everything works well except when a source dataset does not have a CRS
>> defined. Then it crashes with
>>
>> #0  GDALGenImgProjTransform (pTransformArg=0x0, bDstToSrc=1,
>> nPointCount=84, padfX=0xa1093f0, padfY=0xa109690, padfZ=0xa109930,
>> panSuccess=0xa1090a0) at gdaltransformer.cpp:1402
>> #1  0x01f56c6c in GDALWarpOperation::ComputeSourceWindow (this=0xbf7fd214,
>>     nDstXOff=0, nDstYOff=0, nDstXSize=32, nDstYSize=32,
>> pnSrcXOff=0xbf7fd12c, pnSrcYOff=0xbf7fd128, pnSrcXSize=0xbf7fd124,
>> pnSrcYSize=0xbf7fd120) at gdalwarpoperation.cpp:1977
>>
>> gdaltransformer.cpp:1402:
>>
>>         pGCPTransformArg = psInfo->pDstGCPTransformArg;
>>
>> but if I grep gdal for pDstGCPTransformArg it does not seem to be set at
>> all.
>>
>> Could you please give mi a hint? The code is here and above:
>> http://trac.osgeo.org/qgis/browser/trunk/qgis/src/providers/gdal/qgsgdalpro
>> vider.cpp?rev=15400#L625
>>
>> Radim
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>


More information about the gdal-dev mailing list