-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcoords.py
More file actions
44 lines (26 loc) · 978 Bytes
/
Copy pathcoords.py
File metadata and controls
44 lines (26 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from __future__ import annotations
from pyproj import Transformer
def epsg_to_zone(name: str):
assert name.startswith("EPSG:")
return int(name[5:]) - 31464
def zone_to_epsg(zone: int):
assert 2 <= zone <= 5
return f"EPSG:{zone + 31464}"
def to_epsg3857(crs: str, coords: tuple[int, int]):
out_crs = "EPSG:3857"
if crs == out_crs:
return coords
transformer = Transformer.from_crs(crs, out_crs, always_xy=True)
return transformer.transform(*coords)
def to_epsg4326(crs: str, coords: tuple[int, int]):
out_crs = "EPSG:4326"
if crs == out_crs:
return coords
transformer = Transformer.from_crs(crs, out_crs, always_xy=True)
return transformer.transform(*coords)
def to_epsg31468(crs: str, coords: tuple[int, int]):
out_crs = zone_to_epsg(4)
if crs == out_crs:
return coords
transformer = Transformer.from_crs(crs, out_crs, always_xy=True)
return transformer.transform(*coords)