[gdal-dev] GDALCopyWords question

Even Rouault even.rouault at mines-paris.org
Wed Apr 2 11:24:36 PDT 2014


Jo,

you could use GDALRasterIO() that would do the conversion for you.

I think the error in your call to GDALCopyWords() is srcPixelIndex. This 
parameter is supposed to be the number of bytes between 2 values of the source 
buffer, but not the offset of the first value. So you should likely use :

GDALCopyWords( srcBuffer + srcPixelIndex, srcDataType, 0, &srcValue, GDT_Byte, 
0, 1 );

assuming that srcBuffer is a pointer to the srcDataType type and not a char*

Even

> Hi,
> 
> I'm not getting the results I'm expecting using GDALCopy Words() and I was
> wondering if someone might have some insight into where I'm going wrong.
> I'm reading data from a raster block by block. I read the block data into
> an array. I'm calling GDALCopyWords() like this:
> 
> GDALCopyWords( srcBuffer, srcDataType, srcPixelIndex, &srcValue, GDT_Byte,
> 0, 1 );
> 
> where:
> 
> srcBuffer is the array containing the block data
> srcDataType is the data type from the raster band
> srcPixelIndex is the offset from the start of srcBuffer of the pixel I'm
> interested in srcValue is the value of the pixel
> 
> I'm reading a single pixel at a time, hence the dest pixel offset of 0 and
> word count of 1.
> 
> When I use GDALCopyWords() like this on an indexed image I find that each
> block seems to take on the value of the first pixel in the block. For
> example if the first pixel of the block is 128 then I get 128 for all
> other pixels in the block.
> 
> If I index directly into my srcBuffer array then I get the expected values
> i.e.
> 
> if ( srcDataType == GDT_Byte )
> {
>     srcValue = srcBuffer[ srcPixelIndex ];
> }
> 
> so I know that the correct data is in the buffer and that the calculations
> for srcPixelIndex are correct.
> 
> Regards,
> 
> Jo Meder
> 
> 
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev

-- 
Geospatial professional services
http://even.rouault.free.fr/services.html


More information about the gdal-dev mailing list