[gdal-dev] writing a subregion with GDALRasterIO
Joaquim Luis
jluis at ualg.pt
Tue May 8 09:52:11 EDT 2012
Hi,
I am having some troubles in writing a sub-region on an array with
GDALRasterIO.
The story is this. GMT internal grid arrays have a padding of 2 rows and
2 columns around the 'true data region' that is used for boundary
conditions but that need to be striped off upon saving on file.
The following works well when I previously moved all real data in the
'data' array to the beginning of the array. That is, when I sort of
removed the the padding zone.
hDstDS = GDALCreate( hDriver, "mem", nx, ny, n_bands, typeCLASS, NULL );
....
GDALRasterIO( hBand, GF_Write, 0, 0, nx, ny, data, nx, ny,
typeCLASS, 0, 0 );
However, I would like to avoid that step and read directly the zone of
interest from 'data', which because of the padding has actually
(nx+4)x(ny+4) elements. So I tried
GDALRasterIO( hBand, GF_Write, 2, 2, nx, ny, data, nx+4, ny+4,
typeCLASS, 0, 0 );
but get this error:
ERROR 5: mem, band 1: Access window out of range in RasterIO(). Requested
(2,2) of size 37x19 on raster of 37x19.
This happens because of the test on gdalrasterband.cpp
if( nXOff < 0 || nXOff > INT_MAX - nXSize || nXOff + nXSize >
nRasterXSize
but this means I'm stuck here because the nRasterXSize ('nx' in this
case) comes from the GDALCreate() and that I cannot change and so
nXOff + nXSize > nRasterXSize is always true.
Any way out of this gotcha?
Thanks
Joaquim
More information about the gdal-dev
mailing list