[Gdal-dev] GDALWarp Gif Problems

Chris Portka cportka at newwireless.com
Mon Jan 22 21:12:12 EST 2007


I can't seem to get GDAL warp to work on a gif image when converting 
from one UTM zone to another.  If anyone could give me any help at all 
that would be much appreciated.  I've worked on this a long time and 
can't find any documentation that shows I'm doing anything incorrect.  
The exception I get is in this part of the GDAL code (my code follows):

int GDALGenImgProjTransform( void *pTransformArg, int bDstToSrc,
                             int nPointCount,
                             double *padfX, double *padfY, double *padfZ,
                             int *panSuccess )
{
    GDALGenImgProjTransformInfo *psInfo =
        (GDALGenImgProjTransformInfo *) pTransformArg;
    int   i;
    double *padfGeoTransform;
    void *pGCPTransformArg;
    void *pRPCTransformArg;
    void *pTPSTransformArg;
    void *pGeoLocTransformArg;

    if( bDstToSrc )
    {
        padfGeoTransform = psInfo->adfDstGeoTransform;
        pGCPTransformArg = psInfo->pDstGCPTransformArg;
        pRPCTransformArg = NULL;
        pTPSTransformArg = NULL;
        pGeoLocTransformArg = NULL;
    }
    else
    {
        padfGeoTransform = psInfo->adfSrcGeoTransform;
        pGCPTransformArg = psInfo->pSrcGCPTransformArg;    
<-----EXCEPTION HERE
    ...

My code is very similar to the GDAL warp tutorial (the exception I get 
is labeled in the middle of the code):
    GDALDriverH hDriver;
    GDALDataType eDT;
    GDALDatasetH hDstDS;
    GDALDatasetH hSrcDS;

    GDALAllRegister();

    hSrcDS = GDALOpen(fileName.toAscii(), GA_ReadOnly);
    CPLAssert(hSrcDS != NULL);

    eDT = GDALGetRasterDataType(GDALGetRasterBand(hSrcDS,1));

    hDriver = GDALGetDriverByName("GIF");
    CPLAssert(hDriver != NULL);

    char *pszSrcWKT = NULL;
    char *pszDstWKT = NULL;

    OGRSpatialReference srcSR;
    srcSR.SetUTM(18, TRUE);
    srcSR.SetWellKnownGeogCS("WGS84");
    srcSR.exportToWkt(&pszSrcWKT);

    CPLAssert(pszSrcWKT != NULL && strlen(pszSrcWKT) > 0);

    OGRSpatialReference dstSR;
    dstSR.SetUTM(17, TRUE);
    dstSR.SetWellKnownGeogCS("WGS84");
    dstSR.exportToWkt(&pszDstWKT);
 
    void *hTransformArg;
    hTransformArg = GDALCreateGenImgProjTransformer(hSrcDS, pszSrcWKT, 
NULL, pszDstWKT, FALSE, 0, 1);
    CPLAssert(hTransformArg != NULL);

    double adfDstGeoTransform[6];
    int nPixels = 0;
    int nLines = 0;
    CPLErr eErr;
EXCEPTION HAPPENS HERE--->    eErr = GDALSuggestedWarpOutput(hSrcDS, 
GDALGenImgProjTransform,
        hTransformArg, adfDstGeoTransform, &nPixels, &nLines);
    CPLAssert(eErr == CE_None);

    qDebug() << "E";

    GDALDestroyGenImgProjTransformer(hTransformArg);
   
    hDstDS = GDALCreate(hDriver, outputFileName.toAscii(), nPixels, 
nLines, GDALGetRasterCount(hSrcDS), eDT, NULL);

    CPLAssert(hDstDS != NULL);
    GDALSetProjection(hDstDS, pszDstWKT);
    GDALSetGeoTransform(hDstDS, adfDstGeoTransform);

    GDALColorTableH hCT;
    hCT = GDALGetRasterColorTable(GDALGetRasterBand(hSrcDS, 1));
    if(hCT != NULL) {
        GDALSetRasterColorTable(GDALGetRasterBand(hDstDS, 1), hCT);
    }
   
    GDALWarpOptions *warpOptions = GDALCreateWarpOptions();
    warpOptions->hSrcDS = hSrcDS;
    warpOptions->hDstDS = hDstDS;

    warpOptions->nBandCount = 1;
    warpOptions->panSrcBands = (int *) malloc(sizeof(int) * 
warpOptions->nBandCount);
    warpOptions->panSrcBands[0] = 1;

    warpOptions->panDstBands = (int *) malloc(sizeof(int) * 
warpOptions->nBandCount);
    warpOptions->panDstBands[0] = 1;
   
    warpOptions->pfnProgress = GDALTermProgress;

    warpOptions->pTransformerArg = 
GDALCreateGenImgProjTransformer(hSrcDS, pszSrcWKT, NULL, pszDstWKT, 
FALSE, 0.0, 1);
    warpOptions->pfnTransformer = GDALGenImgProjTransform;

    GDALWarpOperation operation;
    operation.Initialize(warpOptions);
    operation.ChunkAndWarpImage(0, 0, GDALGetRasterXSize(hDstDS), 
GDALGetRasterYSize(hDstDS));

    GDALDestroyGenImgProjTransformer(warpOptions->pTransformerArg);
    GDALDestroyWarpOptions(warpOptions);
    GDALClose(hSrcDS);
    GDALClose(hDstDS);



Thanks for any help you can give me,
Chris




More information about the Gdal-dev mailing list