Daan
Daan

Reputation: 357

Can I append a band with different dtype to a geotiff using rasterio?

I have a tiff file named test.tiff. It has 4 bands of dtype uint8. Using these bands I calculated the NDVI which I would now like to save as a fifth band in the test.tiff. Only now I would like to save it as a float32.

Is there a way to do this using rasterio? As geoTiff supports different dtypes for different bands, I guess there should be a way. but up until now I have only been able to find an example on how to do this.

Thanks for any help

Upvotes: 0

Views: 1455

Answers (1)

guampi
guampi

Reputation: 336

Quoting this GDAL mailing list email: https://lists.osgeo.org/pipermail/gdal-dev/2010-August/025657.html

I should note that in theory the TIFF specification allows a mix of sample types, but in practice this is not done in the real world, and libtiff does not support it.

GDAL does support reading mixed band types from a variety of file formats, but not TIFF. As noted, AddBand() can be used in a few format cases to create mixed band types though this is rarely done.

So creating a TIFF file with bands of different types seems a bit complicated.

This being said, I have found a GIS stackexchange saying that it is possible to achieve what you want with a VRT: https://gis.stackexchange.com/a/207067/154376

Upvotes: 1

Related Questions