Skip to content

Commit

Permalink
Make sure that 2D CRS's are promoted to 3D
Browse files Browse the repository at this point in the history
This ensures that transformations with heigths are performed correctly.
Otherwise, in some cases, the vertical component will be disregarded due
to not automatically being promoted to 3D CRS's.

A test has been added to hopefully avoid this situation in the future.
  • Loading branch information
kbevers committed Feb 5, 2025
1 parent 2e81631 commit 78f6929
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
18 changes: 16 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
11 changes: 8 additions & 3 deletions webproj/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 78f6929

Please sign in to comment.