[gdal-dev] Geotiff FillEmptyTiles with no data value?

Even Rouault even.rouault at spatialys.com
Fri May 6 05:14:06 PDT 2016


Le vendredi 06 mai 2016 13:33:36, jramm a écrit :
> NoDataValue is set on a band level and FillEmptyTiles operates at a dataset
> level.
> 
> I've never heard of a geotiff with different nodata per band - is this even
> possible, or would it be reasonable to take the nodatavalue of the 1st band
> and use this to initialise the empty tiles block?

The GDAL_NODATA tag contains a single value, so in GeoTIFF, you can only have 
the same nodata value for all bands. Perhaps this can be overridden in a 
.aux.xml file, but I'm not even sure. So yes using the nodata value of the first 
band is reasonable. Actually I see there's the following variables at the 
GTiffDataset level :

    bool        bNoDataChanged;
    int         bNoDataSet;
    double      dfNoDataValue;

Caution: dfNoDataValue is initialized to -9999 if bNoDataSet is FALSE. But we 
probably want to write zeroes when burning tiles.

> 
> Then there is the problem of the block array being initialised as GBYte:
> 
>     GByte *pabyData = (GByte *) VSI_CALLOC_VERBOSE(nBlockBytes,1);
> 
> NoDataValue is always returned as a double, but actual data type may be
> different values...Am I right in thinking TIFFTileSize will return the
> number of bytes in a block for the data type of the tiff file (e.g. so
> block size = nBlockBytes / sizeof(data_type)?

TIFFTileSize() returns a number of bytes whatever the datatype size is.

> 
> Would something like this be a reasonable way to initialise pabyData
> 
> int typeSize;
> switch (eType){
>   case GDT_Byte:
>       typeSize = sizeof(GByte)
>   case GDT_Int16:
>       typeSize = sizeof(short)
> 
>    ...
> }
> 
> 
> for (int i =0; i < nBlockBytes; i+=typeSize)
> {
>     *pabyData = nullValue;
> }

I'd rather use GDALCopyWords() to do datatype conversion & replication.

GDALCopyWords( &dfNoDataValue, GDT_Float64, 0,
                           pabyData, eDataType,
                           GDALGetDataTypeSizeBytes(eDataType),
                           nBlockBytes / GDALGetDataTypeSizeBytes(eDataType) )


> 
> 
> 
> --
> View this message in context:
> http://osgeo-org.1560.x6.nabble.com/Geotiff-FillEmptyTiles-with-no-data-va
> lue-tp5264310p5264905.html Sent from the GDAL - Dev mailing list archive at
> Nabble.com.
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list