[gdal-dev] Images/datasets with bands with different properties

Even Rouault even.rouault at mines-paris.org
Fri Nov 9 00:28:24 PST 2012


Selon David Strip <gdal at stripfamily.net>:

> I was looking at the API and it appears, that at least in principle a
> multi-band dataset (and hence the associated input file) could have
> bands with different data types since the type is a property of the
> band, not the dataset. Does this actually happen "in the wild"? If so,
> what file types support this scenario?

Yes, this is possible, but uncommon. This is easily doable with the VRT
format due to its nature (XML definition of dataset). The NWT_GRD driver can
also expand 4 bands, the 3 first ones being of type Byte and the 4th one of type
Float32. JPEG2000 can also have mixed data types (I see that at least the Jasper
JPEG2000 and JP2KAK drivers support that), although such datasets are not that
common. There might be a few other drivers that support mixed data types, but
you can probably count them with the fingers of one hand.

I'd note that most algorithms in GDAL probably don't deal ideally with such
situations, in the sense that they will generally select their working data type
as being the type of the first band. This is a weak assumption, in the sense
that it will not lead to crashes, but data type conversion will occur through
RasterIO() calls to convert the actual data type of the band to the working data
type used by the algorithm.

>
> Likewise, the bands apparently can have different size rasters (in terms
> of pixel counts), since the raster size is a property of the band. On
> the other hand, the dataset also has a raster size, as well as the
> overall properties of the raster, such as the geo-location of the origin
> and the size of the pixels. If the band doesn't match the dataset
> properties, what do we know about origin, pixel size, etc?

You give indeed strong reason for why this is not allowed. The nRasterXSize and
nRasterYSize members at the band level must be equal to the ones of the dataset
to which they belong too. This is a strong assumption in all GDAL code. A driver
that wouldn't enforce that would cause chaos.

Traditionnaly if you have files with "bands" of different dimensions, you would
model them as separate subdatasets (see http://gdal.org/gdal_datamodel.html )

If you are interested in robustness, you must also be aware that there are
datasets that can have 0 bands. A specially crafted VRT for example, or more
commonly formats such as HDF4, HDF5, etc.. that expose subdatasets.



More information about the gdal-dev mailing list