Akhil, If you loo at that section of the API Tutorial:
"Using CreateCopy() The GDALDriver::CreateCopy() method can be used fairly simply..." You will see that what you need to do is to call GDALOpen() with GA_ReadOnly passing the input file; then you would need to get a driver, with GDALGetDriverByName(); then call GDALCreateCopy() passing the driver and the output file name. That returns the output dataset pointer read for writing. You don't need to call GDALOpen with GA_Update in that case. You should call GDALGetRasterBand() from the input dataset and from the output dataset. You can find example of that on the last "In C: " source code box on the GDAL API tutorial. Please pay attention to what Frank said about the number of pixels that you are trying to write. He is the boss. :) By the way, I am planning to visit RIT this fall with my son. What Al Pacino and Graig Ferguson are going to be doing together over there? :) (rit.edu). Regards, Ivan > -------Original Message------- > From: Akhil Jaggarwal <[email protected]> > To: [email protected] > Subject: Re: [gdal-dev] Writing pixel values > Sent: Sep 15 '10 14:14 > > 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 <[email protected]> > 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 <[email protected]> > >> To: [email protected] > >> 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 > >> [email protected] > >> http://lists.osgeo.org/mailman/listinfo/gdal-dev > >> > > > _______________________________________________ > gdal-dev mailing list > [email protected] > http://lists.osgeo.org/mailman/listinfo/gdal-dev > _______________________________________________ gdal-dev mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/gdal-dev
