Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct transformation inputs #136

Merged
merged 3 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/coordinate_transformation_api/crs_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def transform_crs(val: CoordinatesType) -> tuple[float, ...]:
):
# check so we can safely cast to tuple[float, float], tuple[float, float, float]
raise ValueError(f"dimension of target-crs should be 2 or 3, is {dim}")
val = cast(tuple[float, float] | tuple[float, float, float], val[0:dim])
val = cast(tuple[float, float] | tuple[float, float, float], val)

# TODO: fix epoch handling, should only be added in certain cases
# when one of the src or tgt crs has a dynamic time component
Expand Down
8 changes: 8 additions & 0 deletions tests/data/test_wgs_epoch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [155000, 463000, 0]
}
}
57 changes: 57 additions & 0 deletions tests/test_geojson_transformation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import math
from contextlib import nullcontext as does_not_raise

import pytest
Expand Down Expand Up @@ -159,3 +160,59 @@ def test_validate_crs_transformed_geojson(feature):
crs_transform(feature_no_exc, "EPSG:28992", "EPSG:4326")
with does_not_raise():
validate_crs_transformed_geojson(feature_no_exc)


def test_wgs_epoch():
with open("tests/data/test_wgs_epoch.json") as f:
data = json.load(f)
feature_2024 = Feature(**data)
feature_2010 = Feature(**data)
feature_epoch_none = Feature(**data)

crs_transform(feature_2024, "EPSG:28992", "EPSG:32631", 2024)
crs_transform(feature_2010, "EPSG:28992", "EPSG:32631", 2010)
crs_transform(feature_epoch_none, "EPSG:28992", "EPSG:32631")

assert feature_2024 != feature_2010
assert feature_2010 != feature_epoch_none
assert feature_epoch_none != feature_2024

coords_2024 = feature_2024.geometry.coordinates
coords_2010 = feature_2010.geometry.coordinates
coords_epoch_none = feature_epoch_none.geometry.coordinates

dif_2024_2010 = 0.34
dif_2024_epoch_none = 0.86

assert (
round(
math.sqrt(
(
(coords_2024[0] - coords_2010[0])
* (coords_2024[0] - coords_2010[0])
)
+ (
(coords_2024[1] - coords_2010[1])
* (coords_2024[1] - coords_2010[1])
)
),
2,
)
== dif_2024_2010
)
assert (
round(
math.sqrt(
(
(coords_2024[0] - coords_epoch_none[0])
* (coords_2024[0] - coords_epoch_none[0])
)
+ (
(coords_2024[1] - coords_epoch_none[1])
* (coords_2024[1] - coords_epoch_none[1])
)
),
2,
)
== dif_2024_epoch_none
)
Loading