[gdal-dev] Writing pixel values

Frank Warmerdam warmerdam at pobox.com
Wed Sep 15 14:06:10 EDT 2010


Akhil Jaggarwal wrote:
> Hi,
> 
> Any comments/suggestions on this issue would be immensely helpful!
> 
> I'm storing the pixel values in a buffer like this:
> 
>  pafScanline = (short int*)CPLMalloc(sizeof(short int)*nxSize*nySize);
> 
> I can read the data alright. The call to GDALRasterIO is being made
> correctly, which I do with:
> 
> GDALRasterIO(hBand, GF_Read, 0, 0, nxSize, nySize,
>                        pafScanline,
>                        nxSize,nySize,
>                        GDT_Int16,
>                        0, 0);
> However, when it comes to the part of writing a pixel data to an
> output file, the call to GDALRasterIO fails:
> 
> for(i = 0; i < nySize; i++) {
>                for(j = 0; j < nxSize; j++) {
> 
>                        if( CE_Failure == GDALRasterIO( hDestDS,
> GF_Write, 0, 0, j, i,
>                          change1, j, i , GDT_Int16, 0,0) ) {
>                                  printf("Write Error!");
>                                  return 1;
>                          }
>              }
>   }

Akhil,

I observe a couple of issues.

First, you passing hDestDS instead of a band to GDALRasterIO when writing.

Second, you seem to want to write a single pixel, but you are passing i,j
as the sizes instead of the position.  Perhaps you mean:

GDALRasterIO( hDestBand, GF_Write,
               i, j, 1, 1,
               change1, 1, 1, GDT_Int16, 0, 0 );

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the gdal-dev mailing list