[Gdal-dev] Filling a RasterBand with a constant value?

Frank Warmerdam warmerdam at pobox.com
Fri May 2 01:45:23 EDT 2003


Simon Perkins wrote:
> Hi Frank,
> 
> I have a need to create a dataset and to ensure that the bands are
> filled with zeros. I'm guessing that GDAL in general makes no guarantees
> that newly created files are zeroed, and that this varies according to
> the underlying driver?
> 
> So, do you think there's any need for a GDALrasterBand::Fill() method?
> Based on past embarrassment, I'd better qualify that with: "Or is there
> already a suitable method that does this?"!
> 
> You could achieve the same effect I suppose with repeated calls to
> WriteBlock(), but you have to set up a dummy array of values to read
> from which seems tedious if you just want to write a constant.
> 
> In general you might want a fill function that takes an arbitrary
> rectangular region and just fills that, but I'd settle for the whole
> band version for now.
> 
> The prototype for the function would be something like:
> 
> virtual CPLErr Fill(double value);

Simon,

My first impression is that this is an unnecessary method, and wouldn't
be used for much.  However, if you wish, you can implement and commit it
as a virtual method on GDALRasterBand.  I would add that the the argument
should be "(double dfRealValue, double dfImaginaryValue = 0.0 )", and that
you might even want to provide for a rectangle to apply it over.

Drivers are not required to initialize new rasters to any particular value
though of course they normally do initialize to zeros.

I would also note that the warp algorithm includes a special option to
initialize the destination raster to a particular value.  It would not
use the Fill() method

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