[Gdal-dev] Re: RasterIO: replicating a value

Carlos A. Rueda carueda at ucdavis.edu
Wed Feb 16 18:35:34 EST 2005


Hi Frank,

Attached is a small test program that recreates (at least for me)
the problem:

$ g++ rasteriotest.cc -lgdal
$ ./a.out
result = 0
$ ls -l
-rwxr-xr-x    1 carueda  carueda     36774 Feb 16 15:03 a.out
-rw-r--r--    1 carueda  carueda    604000 Feb 16 15:12 rasterfilename
-rw-r--r--    1 carueda  carueda       339 Feb 16 15:12 rasterfilename.hdr
-rw-r--r--    1 carueda  carueda      1185 Feb 16 15:09 rasteriotest.cc
	
but rasterfilename should be 1000x1000x1x4 = 4000000 bytes long.
Well, I'm assuming that just creating/deleting the dataset object would
set the whole size of the file (with whatever default band values)
regardless of what data are explicitily written. If this is not the
case, how can I guarantee the desired size without having to write
the whole dataset (my application is certainly filling some regions
but not the whole thing necessarily).

Many thanks for any clarification.

Carlos




Frank Warmerdam wrote:
> On Wed, 16 Feb 2005 11:47:52 -0800, Carlos A. Rueda <carueda at ucdavis.edu> wrote:
> 
>>Hello,
>>
>>I'm trying to make only one call to RasterIO in a 1-band dataset
>>to fill a region with the same value. This is just an example:
>>
>>GDALDataset* dataset = hDriver->Create(
>>    filename,
>>    1000,       //nXSize
>>    1000,       //nYSize
>>    1,          //nBands
>>    GDT_Int32,  //GDALDataType
>>    NULL        //papszParmList
>>);
>>int value = 1234;     // GDT_Int32 in my machine
>>dataset->RasterIO(
>>     GF_Write,
>>     0,            //nXOff,
>>     0,             //nYOff,
>>     200,           //nXSize,
>>     300,           //nYSize,
>>     &value,        //pData,
>>     1,             //nBufXSize,
>>     1,             //nBufYSize,
>>     GDT_Int32,     //eBufType,
>>     1,             //nBandCount,
>>     NULL,          //panBandMap,
>>     0,             //nPixelSpace,
>>     0,             //nLineSpace,
>>     0              //nBandSpace
>>);
>>
>>Is this the right way to obtain the value replicated
>>200x300 times in the upper left region of the dataset?
> 
> 
> Carlos, 
> 
> This looks fine, are you having a problem with it? 
> 
> I would add there is a Fill() method on the GDALRasterBand if
> you find you need to fill the whole thing. 
> 
> Best regards,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rasteriotest.cc
Type: text/x-c++src
Size: 1727 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/gdal-dev/attachments/20050216/de973f8a/rasteriotest.bin


More information about the Gdal-dev mailing list