diff --git a/tests/test_api.py b/tests/test_api.py index e021ef6..2d075f3 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -55,8 +55,8 @@ def _assert_coordinate(entry, expected_json_output, tolerance=1e-6): client = TestClient(app) response = client.get(entry) result = response.json() - print(expected_json_output) - print(result) + print("expected_output:", expected_json_output) + print("results :", result) for key in expected_json_output.keys(): if key not in result.keys(): raise AssertionError @@ -316,6 +316,20 @@ def test_combined_epsg_codes(api_all): } _assert_coordinate(api_entry, expected, tolerance=0.01) +def test_conversion_to_3d(api_all): + """ + Test that a 2D CRS is correctly promoted to 3D when used in + combination with a 3D CRS. + + """ + api_entry = f"/{api_all}/trans/EPSG:4258/EPSG:4258+5799/55.5,11.5,0" + expected = { + "v1": 55.5, + "v2": 11.5, + "v3": -37.4190, + "v4": None, + } + _assert_coordinate(api_entry, expected, tolerance=0.01) def test_crs_return_srid(api_from_v1_1): """ diff --git a/webproj/api.py b/webproj/api.py index cb6aaaf..218c044 100644 --- a/webproj/api.py +++ b/webproj/api.py @@ -14,11 +14,11 @@ from fastapi.middleware.cors import CORSMiddleware from pydantic import BaseModel import pyproj -from pyproj.transformer import Transformer, AreaOfInterest +from pyproj.transformer import Transformer, AreaOfInterest, CRS from webproj.middleware import ProxyHeaderMiddleware -__VERSION__ = "1.2.3" +__VERSION__ = "1.2.4" if "WEBPROJ_LIB" in os.environ: pyproj.datadir.append_data_dir(os.environ["WEBPROJ_LIB"]) @@ -182,8 +182,13 @@ def __init__(self, src, dst): dst_hub = "EPSG:4909" try: + # Explicit promotion to 3D CRS's to ensure vertical + # transformations are picked up correctly. + # Tested in test_conversion_to_3d(). self.epsg_pipeline = Transformer.from_crs( - src, dst_hub, area_of_interest=region + crs_from=CRS(src).to_3d(), + crs_to=CRS(dst_hub).to_3d(), + area_of_interest=region, ) except RuntimeError as error: raise ValueError("Invalid CRS identifier") from error