[gdal-dev] Writing pixel values

Akhil Jaggarwal axj4159 at cs.rit.edu
Wed Sep 15 15:14:07 EDT 2010


Thanks, I understand what I was doing wrong and have appropriately
made some changes.

I created a new band to write using:

GDALRasterBandH hDestBand;

and open the dataset for writing:

hDestDS = GDALOpen( pszDestFileName, GA_Update );


Then I pass metadata:
hDestDS = GDALCreateCopy( hDriver, pszDestFileName, hDataset, FALSE,
                                      NULL, NULL, NULL );

And read all the dataset into pafscanfile buffer: (before starting the for loop)
 GDALRasterIO(hBand, GF_Read, 0, 0, nxSize, nySize,
                        pafScanline,
                        nxSize,nySize,
                        GDT_Int16,
                        0, 0);

However, when it comes to the part of writing the dataset, using:
  for(i = 0; i < nySize; i++) {
                for(j = 0; j < nxSize; j++) {
                         if( CE_Failure == GDALRasterIO( hDestBand,
GF_Write, j, i, 1, 1,
                          change1, 1, 1 , GDT_Int16, 0,0) ) {
                                  printf("Write Error!");
                                  return 1;
                          }

I get the error:

ERROR 5: Access window out of range in RasterIO().  Requested
(1,1) of size 1x1 on raster of 0x0.
Write Error

What am I missing here? It seems I 've to specify the the raster band
size of the ouput band. How can I do that?

Thanks once again.

On Wed, Sep 15, 2010 at 11:58 AM, Ivan Lucena <ivan.lucena at pmldnet.com> wrote:
> Akhil,
>
> How did you create or opened the output? Did you also create the bands before calling GDALRasterIO?
>
> See examples on: http://gdal.org/gdal_tutorial.html
>
> Regards,
>
> Ivan
>
>
>>  -------Original Message-------
>>  From: Akhil Jaggarwal <axj4159 at cs.rit.edu>
>>  To: gdal-dev at lists.osgeo.org
>>  Subject: [gdal-dev] Writing pixel values
>>  Sent: Sep 15 '10 10:52
>>
>>  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;
>>                           }
>>               }
>>    }
>>
>>  Where change1 is a variable to hold pixel data that I want to change.
>>  It's declared in the following manner:
>>
>>  short int*change1;
>>  change1 = malloc(sizeof(short int));
>>  *change1 = 1;
>>
>>  I can't get what exactly am I missing. The file i'm using is a tiled,
>>  16 bit signed TIFF.
>>
>>  How do I change the value at a pixel location?
>>
>>  Thanks!
>>  _______________________________________________
>>  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