[Gdal-dev] Datatype of bands

Frank Warmerdam warmerdam at pobox.com
Fri Aug 18 15:42:03 EDT 2006


Matt Hanson wrote:
> Hi,  I have a couple questions regarding the data type of bands in a single
> dataset.   Each spectral band in a file could potentially have a different
> datatype.
> 
> 1) Is there an easy way to retrieve the smallest data type that can hold
> the values across all bands, or only by iterating through with
> GetRasterband()->GetRasterDataType() and calls to GDALDataTypeUnion()?

Matt,

There is no convience function for this.   Your approach is the right one.

> 2) It looks like GDAL cannot *create* a file with varying data types across
> spectral bands unless it is done with first a Create(), then using
> AddBands() to add each band individually.  But AddBands() isn't supported
> by all data formats.  I haven't been able to find a list of formats that
> support AddBand...did I miss it?

There is no list of formats supporting AddBand(). You would pretty much have
to inspect the implementations.  In practice I think there are very very
few that do support it.  possibly only the MEM and VRT formats.

Format drivers also have the option of honouring the band data type
from the source in the CreateCopy() method.  In practice most just
grab the type of the first band and assume the rest are the same.

Generally speaking it is rare for image files to have different types for
different bands, and while GDAL can expose it when it occurs, many drivers
won't capture it when copying a dataset.

It would be nice if we were more systematic about reporting failures to
honour the original band types when copying.

> 3) Not so much a GDAL question, but I was wondering how common users out
> there have found different datatypes vs. bands to be.  I don't think it's
> all that common unless perhaps elevation maps are bundled in with data, or
> the format contains both raw and calibrated data.  But I don't want to
> immediately make the assumption that all datasets will have identical
> datatypes across all bands. I need to make a decision about if I need to
> support creation of multi-datatype files and was hoping to get feedback on
> if users out there felt this was a safe assumption or a bad one.

Right, it is quite rare.  I think the most common formats to do it are
PCIDSK and Erdas Imagine formats, but even then it is a very small
number of all datasets.

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    | President OSGF, http://osgeo.org




More information about the Gdal-dev mailing list