[gdal-dev] Warping an image using GDALAutoCreateWarpedVRT() and other questions

Adeel Raza adeel.raza at crc.gc.ca
Thu Jul 9 14:38:13 EDT 2009


Hi,

I'm using the "GTiff" driver and using it to create an empty file. 
Afterwards I write data to the (one and only) rasterband using a float 
array as the buffer (the GDALDataType I use for the GDALDataset is 
GDT_Float32 - I believe that should be ok). Then I warp the image  
using  the GDALAutoCreateWarpedVRT() function. I have noticed that after 
the image is warped, the number of pixels are not the same as the 
original TIFF image. Is this normal? I know this sounds like a stupid 
question, but I need to be sure.

Secondly I was also wondering how the GDALRasterBand::RasterIO() 
function feeds data into the raster band. I make a function call to the 
RasterIO function according to the following code:

    GDALDriver *tifDriver;
    GDALDataset *srcDataset;

    tifDriver = (GDALDriver *)GDALGetDriverByName("GTiff");
    assert(tifDriver != NULL);
    srcDataset = tifDriver->Create("srcDataset.tif", nCols, nRows, 1, 
GDALDataType::GDT_Float32, NULL);
    assert(srcDataset != NULL);

    srcDataset->GetRasterBand(1)->RasterIO(GF_Write, 0, 0, nCols, nRows, 
realCellVals, nCols, nRows, GDALDataType::GDT_Float32, 0 , 0);

Both nCols and nRows are unsigned shorts and realCellVals is defined as 
"float *realCellVals = new float[nCols*nRows];". I have filled 
realCellValls so that the row at the top of the raster image is the 
first row and the row at the bottom of the raster image is the last row 
in the array. Also columns indices increase from left to right. Will 
this implementation work properly with the RasterIO() function or do I 
need to arrange my array in another way? The reason why this is critical 
is so that I can create a north up TIFF image, warp it to the desired 
projection system, and get an affine geo transform of the warped north 
up image so that GT[2] and GT[4] are 0 (GT is the returned affine geo 
transform from the function - GDALDataset::GetGeoTransform()).

Lastly I initially tried the same approach using a virtual database and 
creating it in memory using the GDALDriver::Create() function. I tried 
using the GDALRasterBand::RasterIO() function on the database but I got 
an error saying "writing to VRTWarpedRasterBands is not supported". 
Therefore I had to use the tiff format to warp the image. Is there 
anyway to bypass this so that I don't have to create a temporary tiff 
file to warp my image?

Any help would be greatly appreciated. Thanks.

Best Regards,
Adeel.




More information about the gdal-dev mailing list