From 07a7af50c915a39e0108e87b66eb8837fd8a6e77 Mon Sep 17 00:00:00 2001 From: Alice Fage Date: Mon, 12 Feb 2024 13:32:40 +1300 Subject: [PATCH] fix: handle 50k imagery filenames TDE-1014 (#845) * fix: handle 50k imagery filenames * fix: remove extraneous lines * docs: clarify scales supported --- scripts/tile/tests/tile_index_test.py | 6 ++++++ scripts/tile/tile_index.py | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts/tile/tests/tile_index_test.py b/scripts/tile/tests/tile_index_test.py index 5b7e6433b..288d9bfe8 100644 --- a/scripts/tile/tests/tile_index_test.py +++ b/scripts/tile/tests/tile_index_test.py @@ -10,6 +10,12 @@ def test_get_bounds_from_name() -> None: assert expected_bounds == bounds +def test_get_bounds_from_50k_name() -> None: + expected_bounds = Bounds(Point(x=1180000, y=4758000), Size(width=24_000, height=36_000)) + bounds = get_bounds_from_name("CK08") + assert expected_bounds == bounds + + @pytest.mark.dependency() def test_get_tile_offset() -> None: expected_bounds = Bounds(Point(x=8640, y=28440), Size(width=240, height=360)) diff --git a/scripts/tile/tile_index.py b/scripts/tile/tile_index.py index c27fa90b4..1072d01d1 100644 --- a/scripts/tile/tile_index.py +++ b/scripts/tile/tile_index.py @@ -1,3 +1,4 @@ +import re from typing import NamedTuple, Union from scripts.tile.util import charcodeat @@ -42,6 +43,14 @@ def get_bounds_from_name(tile_name: str) -> Bounds: Returns: a `Bounds` object """ + # check for 50k imagery + if re.match(r"^[A-Z]{2}\d{2}$", tile_name): + origin = get_mapsheet_offset(tile_name) + return Bounds( + Point(x=origin.x, y=origin.y), + Size(SHEET_WIDTH, SHEET_HEIGHT), + ) + name_parts = tile_name.split("_") map_sheet = name_parts[0] # should be in [10_000, 5_000, 2_000, 1_000, 500] @@ -104,9 +113,9 @@ def get_tile_offset(grid_size: int, x: int, y: int) -> Bounds: """Get the tile offset from its coordinate and the grid size Args: - grid_size: a size from in [10_000, 5_000, 2_000, 1_000, 500] - x: upper left cooridinate x - y: upper left cooridinate y + grid_size: a size in [10_000, 5_000, 2_000, 1_000, 500] + x: upper left coordinate x + y: upper left coordinate y Returns: a `Bounds` object