You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was working on adding GDAL Metadata to a GeoTiff file, as it is needed for getting the minimum and maximum values when using Geotiff.js. I tried adding the STATISTICS_MINIMUM and STATISTICS_MAXIMUM in a few ways, but wasn't able to get it to work until I found out about the undocumented band_tags key for the tags argument of to_raster.
It would great to have documentation of this features, perhaps with an example. I could add a mention of it in the docstring. Would there be other documentation that you think could be helpful?
As described in Envi header information is stripped on write #635 the tags are flattened when read into attributes on read, so band_tags do not round trip between read and write. It seems that XArray will allow for dictionary based attributes. Would this be a feature of interest? I guess it would need to have a toggle on read, as NetCDF doesn't allow dicts as attributes.
I am not sure that I follow how the Dataset/DataArray tags would be handled similar to rasterio. Would this imply making an additional attribute to hold the tags?
Here are my successful and failed examples. I used the attached test file from the Geotiff.js repository. nt_20201024_f18_nrt_s.tif.zip
This resulted in the statistics metadata being not being assigned to the bands, but the nodata value was assigned and a new description band field was added.
My next attempt was to try to write the whole dataset to raster. To try and differentiate between the band tags and the dataset tags. Of course didn't work as only dataarrays can be written.
I then tried adding the tiff tag for GDALMetadata 42112, with the XML added, as I saw when using tiffinfo that the XML from the good file had an extra sample keyword compared to the round-tripped file.
This didn't work as I wasn't supposed to be adding tiff tags directly and the XML wasn't parsed correctly.
Finally, I dug around in the rioxarray code to see why the description field was correctly added to the band, which was when I found that band tags worked.
I updated my code to add the statistics I needed as band tags:
Activity
snowman2 commentedon Aug 3, 2024
I wonder if it would be helpful to have an interface to writing tags to the Dataset/DataArray similar to rasterio's: https://rasterio.readthedocs.io/en/stable/topics/tags.html#writing-tags
snowman2 commentedon Aug 3, 2024
@neda-dtu, mind providing examples of what your failed attempts looked like?
neda-dtu commentedon Aug 5, 2024
I am not sure that I follow how the Dataset/DataArray tags would be handled similar to rasterio. Would this imply making an additional attribute to hold the tags?
Here are my successful and failed examples. I used the attached test file from the Geotiff.js repository. nt_20201024_f18_nrt_s.tif.zip
The metadata from
gdalinfolooks like:My first attempt was to just roundtrip the file:
This resulted in the statistics metadata being not being assigned to the bands, but the nodata value was assigned and a new description band field was added.
My next attempt was to try to write the whole dataset to raster. To try and differentiate between the band tags and the dataset tags. Of course didn't work as only dataarrays can be written.
I then tried adding the tiff tag for GDALMetadata 42112, with the XML added, as I saw when using
tiffinfothat the XML from the good file had an extrasamplekeyword compared to the round-tripped file.original tiffinfo
roundtripped tiffinfo
This didn't work as I wasn't supposed to be adding tiff tags directly and the XML wasn't parsed correctly.
Finally, I dug around in the rioxarray code to see why the description field was correctly added to the band, which was when I found that band tags worked.
I updated my code to add the statistics I needed as band tags:
Then I got the idea that I could add the
band_tagsattribute to the dataset for round-trip, which worked in my test.snowman2 commentedon Aug 5, 2024
The idea would be to add
ds.rio.write_tagsor something so you don't have to worry about the intrernals