Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tidy up geometry and bbox TDE-522 #227

Merged
merged 2 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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