feat: Fetch tile data from GeoTIFF/Overview#22
Conversation
src/async_geotiff/_geotiff.py
Outdated
|
|
||
| # Check if the primary IFD has a mask | ||
| if len(tiff.ifds) >= 2 and is_mask_ifd(tiff.ifds[ifd_idx]): # noqa: PLR2004 | ||
| object.__setattr__(self, "_mask_ifd", tiff.ifds[ifd_idx]) |
There was a problem hiding this comment.
I don't fully remember the COG architecture, but I think at one point the Mask where stored after all the image IFD (at least when not using the COG driver)
Does async-geotiff read the ghost header https://gdal.org/en/stable/drivers/raster/cog.html#header-ghost-area ?
also might specify in the library that we don't support external overview/mask 🤷
There was a problem hiding this comment.
Ah. I just assumed it would always be data/mask/overview/mask overview.
No, we don't currently read the ghost header. @geospatial-jeff suggested not to in developmentseed/async-tiff#7. I think we might want to allow injecting support for it. In theory that might be something we could inject.
I think in the future, supporting external overview/mask would be possible, but no, not right now.
There was a problem hiding this comment.
In 8f02864 (this PR) I implemented a cleaner association of data ifds to masks:
-
First create
dictsmapping from(image height, image width): (ifd index, ifd):data_ifds: dict[tuple[int, int], tuple[int, ImageFileDirectory]] = {} mask_ifds: dict[tuple[int, int], tuple[int, ImageFileDirectory]] = {}
-
Then iterate over the data ifds from largest to smallest. If there's a mask IFD of the same height and width, then associate the mask IFD with that data IFD.
Change list
fetch_tileandfetch_tileson theGeoTIFFclass (for fetching full-resolution tiles) and on theOverviewclass (for fetching reduced-resolution tiles)asyncio.gatheron multiple Python async requests.fetch_tilehas the same signature on bothGeoTIFFand onOverview.Arrayclass. TheArrayholds numpy arrays for the data (and possibly also for the mask). It also holds the per-tile affine transform, a reference to the image's CRS, and height and width.TODO:
cc @geospatial-jeff