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

Simon Perkins s.perkins at lanl.gov
Thu May 1 19:00:42 EDT 2003


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);

and the default implementation in GDALRasterBand would make use of the
WriteBlock() method. Formats could optionally override it with a more
efficient version if available.

I'd be happy to go ahead and add this to CVS if you think it's a
reasonable plan. What you think?

Cheers,

Sy





More information about the Gdal-dev mailing list