Debian Codegraph @

general/g.region/tests/g_region_crs_test.py

raw
1 import os
2
3 import grass.script as gs
4 from grass.tools import Tools
5
6
7 def test_crs_xy(tmp_path):
8 """Check general XY project"""
9 project = tmp_path / "test"
10 gs.create_project(project)
11 with (
12 gs.setup.init(project, env=os.environ.copy()) as session,
13 Tools(session=session) as tools,
14 ):
15 data = tools.g_region(flags="p", format="json")
16 assert data["crs"]["type_code"] == 0
17 assert data["crs"]["type"] == "xy"
18 # We test the value we are returning (but the value is not part of the API).
19 assert data["crs"]["name"] == "x,y"
20 assert data["crs"]["zone"] is None
21
22
23 def test_crs_utm_north(tmp_path):
24 """Check UTM 17N project"""
25 project = tmp_path / "test"
26 gs.create_project(project, epsg="6346")
27 with (
28 gs.setup.init(project, env=os.environ.copy()) as session,
29 Tools(session=session) as tools,
30 ):
31 data = tools.g_region(flags="p", format="json")
32 assert data["crs"]["type_code"] == 1
33 assert data["crs"]["type"] == "utm"
34 # We simply test the value we are returning now, but more detailed name would be nice.
35 assert data["crs"]["name"] == "UTM"
36 assert data["crs"]["zone"] == 17
37
38
39 def test_crs_utm_south(tmp_path):
40 """Check UTM 17S project"""
41 project = tmp_path / "test"
42 gs.create_project(project, epsg="32717")
43 with (
44 gs.setup.init(project, env=os.environ.copy()) as session,
45 Tools(session=session) as tools,
46 ):
47 data = tools.g_region(flags="p", format="json")
48 assert data["crs"]["type_code"] == 1
49 assert data["crs"]["type"] == "utm"
50 # We simply test the value we are returning now, but more detailed name would be nice.
51 assert data["crs"]["name"] == "UTM"
52 assert data["crs"]["zone"] == -17
53
54
55 def test_crs_ll(tmp_path):
56 """Check latitude/longitude (WGS84) project"""
57 project = tmp_path / "test"
58 gs.create_project(project, epsg="4326")
59 with (
60 gs.setup.init(project, env=os.environ.copy()) as session,
61 Tools(session=session) as tools,
62 ):
63 data = tools.g_region(flags="p", format="json")
64 assert data["crs"]["type_code"] == 3
65 assert data["crs"]["type"] == "ll"
66 # We test the value we are returning (but the value is not part of the API).
67 assert data["crs"]["name"] == "Latitude-Longitude"
68 assert data["crs"]["zone"] is None
69
70
71 def test_crs_other_epsg(tmp_path):
72 """Check other CRS (NC SPM) project from EPSG
73
74 Note: In the past, projection code 2 was used for US state plane CRS in feet,
75 but we are not supporting or testing this.
76 """
77 project = tmp_path / "test"
78 gs.create_project(project, epsg="3358")
79 with (
80 gs.setup.init(project, env=os.environ.copy()) as session,
81 Tools(session=session) as tools,
82 ):
83 data = tools.g_region(flags="p", format="json")
84 assert data["crs"]["type_code"] == 99
85 assert data["crs"]["type"] == "other"
86 # We loosely test for the name associated with the EPSG code.
87 # It may as well be, e.g., Lambert Conformal Conic.
88 # (But we should not get 'other or unknown projection' type of text.)
89 name = data["crs"]["name"]
90 assert "North Carolina".lower() in name.lower()
91 assert "NAD83".lower() in name.lower()
92 assert data["crs"]["zone"] is None
93
94
95 def test_crs_other_custom(tmp_path):
96 """Check a custom CRS project"""
97 project = tmp_path / "test"
98 gs.create_project(project, proj4="+proj=merc +lat_ts=56.5 +ellps=GRS80")
99 with (
100 gs.setup.init(project, env=os.environ.copy()) as session,
101 Tools(session=session) as tools,
102 ):
103 data = tools.g_region(flags="p", format="json")
104 assert data["crs"]["type_code"] == 99
105 assert data["crs"]["type"] == "other"
106 assert data["crs"]["name"] is None
107 assert data["crs"]["zone"] is None