cogeotiff / rio-cogeo

Cloud Optimized GeoTIFF creation and validation plugin for rasterio
https://cogeotiff.github.io/rio-cogeo/
BSD 3-Clause "New" or "Revised" License
308 stars 42 forks source link

Flag GeoTIFFs with invalidated optimizations as invalid COGs #260

Closed mplough-kobold closed 1 year ago

mplough-kobold commented 1 year ago

This PR modifies rio cogeo validate to flag GeoTIFFs with modifications known to GDAL to invalidate the optimized layout as invalid COGs. It does so by checking the ghost header, if present.

When I followed up on the discussion created from #258, I figured out that GDAL adds ghost headers to GeoTIFF files. GDAL >= 3.1 marks KNOWN_INCOMPATIBLE_EDITION=YES in ghost headers when it writes out a modified COG file:

This file used to have optimizations in its layout, but those have been, at least partly, invalidated by later changes

With https://github.com/OSGeo/gdal/pull/2832, GDAL reports the content of the ghost header area in a way that's accessible to rasterio, allowing us to easily check its contents.

I verified that get_tag_item returns None if a tag is not present -- so compatibility with non-GDAL COGs is preserved.

vincentsarago commented 1 year ago

🙏 thanks @mplough-kobold for looking deeper into this!

I think the changes make sense, I'll merge and make a 3.5.2 release 🙏