Skip to content

Commit

Permalink
fix: tidy up geometry and bbox TDE-522 (#227)
Browse files Browse the repository at this point in the history
* fix: tidy up geometry and bbox

* fix: test formatting
  • Loading branch information
amfage authored Nov 24, 2022
1 parent 7e547d6 commit 02b06b5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions scripts/files/geotiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions scripts/stac/imagery/item.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions scripts/stac/tests/item_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"]
Expand Down

0 comments on commit 02b06b5

Please sign in to comment.