From 1424b16b9d03ab997f74b47d31e374b2adc62b8f Mon Sep 17 00:00:00 2001 From: Sylvain Gaudan Date: Wed, 17 Jul 2024 10:50:05 +0200 Subject: [PATCH] get first key/value from gdalinfo --- .../aproc/proc/ingest/drivers/impl/tiff.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/extensions/aproc/proc/ingest/drivers/impl/tiff.py b/extensions/aproc/proc/ingest/drivers/impl/tiff.py index e18ca5de..4f7c60e3 100644 --- a/extensions/aproc/proc/ingest/drivers/impl/tiff.py +++ b/extensions/aproc/proc/ingest/drivers/impl/tiff.py @@ -87,16 +87,21 @@ def to_item(self, url: str, assets: list[Asset]) -> Item: gdalOptions = gdal.InfoOptions(format='json') gdalInfo = gdal.Info(url, options=gdalOptions) - - try: - creation_time = dateutil.parser.parse(gdalInfo.get("metadata", {}).get("", {}).get("creation_time", "")) - except dateutil.parser.ParserError: + metadata_keys = list(gdalInfo.get("metadata", {})) + if metadata_keys: + description = gdalInfo.get("metadata", {}).get(metadata_keys[0], {}).get("title", "TIFF file") + try: + creation_time = dateutil.parser.parse(gdalInfo.get("metadata", {}).get(metadata_keys[0], {}).get("creation_time", "")) + except dateutil.parser.ParserError: + creation_time = None + else: + description = "TIFF file" creation_time = None - description = gdalInfo.get("metadata", {}).get("", {}).get("title", "TIFF file") - with rasterio.open(url) as dataset: + + with rasterio.open(url) as dataset: for v in zip(dataset.indexes, dataset.descriptions): bands.append(Band(name="Band " + str(v[0]), common_name="Band " + str(v[0]), description=v[1] if v[1] else "Band " + str(v[0]))) - # GET THE GEO EXTEND + # GET THE GEO EXTENT # Read the dataset's valid data mask as a ndarray. mask = dataset.dataset_mask() # Extract feature shapes and values from the array.