From 02b06b51a58650ffbe1a18a4bedd4996251c6c16 Mon Sep 17 00:00:00 2001 From: Alice Fage Date: Fri, 25 Nov 2022 09:09:32 +1300 Subject: [PATCH] fix: tidy up geometry and bbox TDE-522 (#227) * fix: tidy up geometry and bbox * fix: test formatting --- scripts/files/geotiff.py | 4 ++-- scripts/stac/imagery/item.py | 6 +++--- scripts/stac/tests/item_test.py | 8 ++++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/scripts/files/geotiff.py b/scripts/files/geotiff.py index 6a9f235b1..f86c82d91 100644 --- a/scripts/files/geotiff.py +++ b/scripts/files/geotiff.py @@ -5,7 +5,7 @@ def get_extents(gdalinfo_result: Dict[Any, Any]) -> Tuple[List[List[float]], List[float]]: - geometry = gdalinfo_result["wgs84Extent"]["coordinates"][0] - bbox = list(Polygon(geometry).bounds) + geometry = gdalinfo_result["wgs84Extent"] + bbox = Polygon(geometry["coordinates"][0]).bounds return geometry, bbox diff --git a/scripts/stac/imagery/item.py b/scripts/stac/imagery/item.py index 7c34a6c7a..1959d6d67 100644 --- a/scripts/stac/imagery/item.py +++ b/scripts/stac/imagery/item.py @@ -1,5 +1,5 @@ import os -from typing import Any, Dict, List +from typing import Any, Dict, List, Tuple from scripts.stac.util import checksum from scripts.stac.util.STAC_VERSION import STAC_VERSION @@ -34,8 +34,8 @@ def update_datetime(self, start_datetime: str, end_datetime: str) -> None: "datetime": None, } - def update_spatial(self, geometry: List[List[float]], bbox: List[float]) -> None: - self.stac["geometry"] = {"type": "Polygon", "coordinates": [geometry]} + def update_spatial(self, geometry: Dict[str, List[float]], bbox: Tuple[float]) -> None: + self.stac["geometry"] = geometry self.stac["bbox"] = bbox def add_collection(self, collection_id: str) -> None: diff --git a/scripts/stac/tests/item_test.py b/scripts/stac/tests/item_test.py index 357b3cc5d..7c7f872fe 100644 --- a/scripts/stac/tests/item_test.py +++ b/scripts/stac/tests/item_test.py @@ -5,7 +5,10 @@ def test_imagery_stac_item(mocker) -> None: # type: ignore # mock functions that interact with files - geometry = [[1799667.5, 5815977.0], [1800422.5, 5815977.0], [1800422.5, 5814986.0], [1799667.5, 5814986.0]] + geometry = { + "type": "Polygon", + "coordinates": [[[1799667.5, 5815977.0], [1800422.5, 5815977.0], [1800422.5, 5814986.0], [1799667.5, 5814986.0]]], + } bbox = [1799667.5, 5815977.0, 1800422.5, 5814986.0] checksum = "1220cdef68d62fb912110b810e62edc53de07f7a44fb2b310db700e9d9dd58baa6b4" mocker.patch("scripts.stac.util.checksum.multihash_as_hex", return_value=checksum) @@ -23,7 +26,8 @@ def test_imagery_stac_item(mocker) -> None: # type: ignore assert item.stac["properties"]["start_datetime"] == start_datetime assert item.stac["properties"]["end_datetime"] == end_datetime assert item.stac["properties"]["datetime"] is None - assert item.stac["geometry"]["coordinates"] == [geometry] + assert item.stac["geometry"]["coordinates"] == geometry["coordinates"] + assert item.stac["geometry"] == geometry assert item.stac["bbox"] == bbox assert item.stac["assets"]["visual"]["file:checksum"] == checksum assert {"rel": "self", "href": f"./{id_}.json", "type": "application/json"} in item.stac["links"]