|
1 | 1 | import re |
2 | 2 | from typing import NamedTuple |
3 | 3 |
|
| 4 | +from topo_imagery_common.epsg import EpsgNumber |
4 | 5 | from topo_imagery_gdal.tile.util import charcodeat |
5 | 6 |
|
6 | 7 | SHEET_WIDTH = 24_000 |
|
16 | 17 | CHAR_A = charcodeat("A", 0) |
17 | 18 | CHAR_S = charcodeat("S", 0) |
18 | 19 |
|
19 | | -MAINLAND_EPSG = 2193 |
| 20 | +MAINLAND_EPSG = EpsgNumber.NZTM_2000 |
20 | 21 | """ EPSG code of the mainland NZTM50 mapsheet grid (NZGD2000 / NZTM2000) """ |
21 | | -CHATHAM_EPSG = 3793 |
| 22 | +CHATHAM_EPSG = EpsgNumber.CITM_2000 |
22 | 23 | """ EPSG code of the Chatham Islands mapsheet grid (NZGD2000 / CITM2000) """ |
23 | 24 |
|
24 | 25 |
|
@@ -63,41 +64,21 @@ class Bounds(NamedTuple): |
63 | 64 | "CI06": Point(x=3_506_000, y=5_104_000), # Pitt Island (Rangiauria) |
64 | 65 | } |
65 | 66 |
|
66 | | - |
67 | | -def get_chatham_mapsheet_offset(sheet_code: str) -> Point: |
68 | | - """Look up the origin point for a Chatham Islands mapsheet code. |
69 | | -
|
70 | | - Args: |
71 | | - sheet_code: Chatham Islands topo 50 map sheet code eg "CI06" |
72 | | -
|
73 | | - Returns: |
74 | | - Point: The top left point of the mapsheet, in EPSG:3793 |
75 | | -
|
76 | | - Example: |
77 | | - >>> get_chatham_mapsheet_offset("CI06") |
78 | | - Point(x=3506000, y=5104000) |
79 | | - """ |
80 | | - origin = CHATHAM_SHEET_ORIGINS.get(sheet_code[:4]) |
81 | | - if origin is None: |
82 | | - raise ValueError(f"Unknown Chatham Islands map sheet: {sheet_code}; known sheets: {sorted(CHATHAM_SHEET_ORIGINS)}") |
83 | | - return origin |
84 | | - |
85 | | - |
86 | 67 | def get_bounds_from_name(tile_name: str, target_epsg: int = MAINLAND_EPSG) -> Bounds: |
87 | 68 | """Get the origin coordinates and size of the tile from its name. |
88 | 69 |
|
89 | 70 | Args: |
90 | 71 | tile_name: the tile name as `sheetCode_gridSize_tileId` |
91 | | - target_epsg: EPSG code of the mapsheet grid the tile is named against; only |
| 72 | + target_epsg: EPSG code of the mapsheet grid for the tile. |
92 | 73 | `MAINLAND_EPSG` (2193) and `CHATHAM_EPSG` (3793) are supported |
93 | 74 |
|
94 | 75 | Returns: |
95 | 76 | a `Bounds` object |
96 | 77 | """ |
97 | | - if target_epsg == CHATHAM_EPSG: |
98 | | - get_offset = get_chatham_mapsheet_offset |
99 | | - elif target_epsg == MAINLAND_EPSG: |
| 78 | + if target_epsg == MAINLAND_EPSG: |
100 | 79 | get_offset = get_mapsheet_offset |
| 80 | + elif target_epsg == CHATHAM_EPSG: |
| 81 | + get_offset = get_chatham_mapsheet_offset |
101 | 82 | else: |
102 | 83 | raise ValueError( |
103 | 84 | f"Unsupported target EPSG:{target_epsg} for mapsheet lookup; supported: {MAINLAND_EPSG}, {CHATHAM_EPSG}" |
@@ -169,6 +150,26 @@ def get_mapsheet_offset(sheet_code: str) -> Point: |
169 | 150 | return Point(x=SHEET_WIDTH * x + SHEET_ORIGIN_LEFT, y=SHEET_ORIGIN_TOP - SHEET_HEIGHT * y) |
170 | 151 |
|
171 | 152 |
|
| 153 | +def get_chatham_mapsheet_offset(sheet_code: str) -> Point: |
| 154 | + """Look up the origin point for a Chatham Islands mapsheet code. |
| 155 | +
|
| 156 | + Args: |
| 157 | + sheet_code: Chatham Islands topo 50 map sheet code eg "CI06" |
| 158 | +
|
| 159 | + Returns: |
| 160 | + Point: The top left point of the mapsheet, in EPSG:3793 |
| 161 | +
|
| 162 | + Example: |
| 163 | + >>> get_chatham_mapsheet_offset("CI06") |
| 164 | + Point(x=3506000, y=5104000) |
| 165 | + """ |
| 166 | + origin = CHATHAM_SHEET_ORIGINS.get(sheet_code[:4]) |
| 167 | + if origin is None: |
| 168 | + raise ValueError(f"Unknown Chatham Islands map sheet: {sheet_code}. Known sheets: {sorted(CHATHAM_SHEET_ORIGINS)}") |
| 169 | + return origin |
| 170 | + |
| 171 | + |
| 172 | + |
172 | 173 | def get_tile_offset(grid_size: int, x: int, y: int) -> Bounds: |
173 | 174 | """Get the tile offset from its coordinate and the grid size |
174 | 175 |
|
|
0 commit comments