Le vendredi 16 septembre 2016 22:57:13, Andrew Bell a écrit :
> Hi,
> 
> My code for creating a Tiff raster looks something like this:
> 
> int nBands = 5;
> dataset->Create(filename, width, height, nBands, ...);
> 
> for (int i = 1; i <= nBands; ++i)
> {
>     GDALRasterBand *band = dataset->GetRasterBand(i);
>     band->SetDescription(someString);
>     band->WriteBlock(someData);
> }
> 
> It appears that only the description to band 1 is written (it's the only
> one reported by gdalinfo).  A little debugging leads me to believe that
> what's happening is that WriteBlock() invokes Crystalize() ->
> WriteMetadata(), which takes care of setting the band description.  But
> once Crystalize() is called, it sets a flag so as to be a NOOP in future
> calls.  I'm not using streaming.
> 
> I'm trying to understand if this behavior is by design, a limitation that I
> can't find in the documentation or a bug.

It's a limitation due to how libtiff works mostly and/or how we use it (but 
mostly how libtiff works, and a bit how the TIFF format itself makes it hard). 
Basically for GTiff, you need to do all operations that affect metadata, in a 
broad meaning, ie georeferencing, description, offsets, color table, TIFF & 
GDAL metadata, etc... before writing any imagery.  If we allowed to change 
metadata after crzystalization, this would require rewriting the whole set of 
TIFF tags at the end of file each time their serialized form increase.

So rewrite your loop into 2: one to set all descriptions, and another one to 
write blocks.

Other formats may have similar limitations, so it is generally safe to proceed 
this way in general.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to