Skip to content
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
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,3 @@ werkzeug==3.1.8
# flask
# flask-cors

opengeodeweb-microservice==1.*,>=1.4.0
14 changes: 12 additions & 2 deletions src/opengeodeweb_back/crs/crs_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def geographic_coordinate_systems(
if is_3d
else og_geosciences.GeographicCoordinateSystem2D.geographic_coordinate_systems()
)
return {info.authority_code(): info for info in infos}
# A height-only CRS cannot place X and Y: converting them fails afterwards
vertical = vertical_coordinate_systems()
return {info.authority_code(): info for info in infos if info.authority_code() not in vertical}


def known_geographic_info(
Expand Down Expand Up @@ -188,6 +190,13 @@ def area_of_use(authority: str, code: str) -> list[tuple[float, float, float, fl
return [(float(s), float(n), float(w), float(e)) for s, n, w, e in rows]


@functools.cache
def vertical_coordinate_systems() -> frozenset[str]:
"""Height or depth only CRS PROJ knows, as "AUTHORITY:CODE"."""
rows = _query_proj_database("SELECT auth_name, code FROM vertical_crs", ()) or []
return frozenset(f"{authority}:{code}" for authority, code in rows)


def _overlaps(
latitudes: tuple[float, float],
longitudes: tuple[float, float],
Expand All @@ -206,7 +215,8 @@ def coordinates_implausible(
geode_object: CrsGeodeObject, info: og_geosciences.GeographicCoordinateSystemInfo
) -> bool:
"""Whether the data XY extent, read in info, misses the area where info is used."""
boxes = [mesh.bounding_box() for mesh in geode_object.crs_meshes()]
# Empty meshes, like blocks of a model built from surfaces, have no bounding box
boxes = [mesh.bounding_box() for mesh in geode_object.crs_meshes() if mesh.nb_vertices() > 0]
# Without mesh, the infinite bounds below mark the data as implausible
bounds = (
min((box.min().value(0) for box in boxes), default=math.inf),
Expand Down
26 changes: 26 additions & 0 deletions tests/test_crs_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,22 @@ def test_unknown_crs(client: FlaskClient) -> None:
assert response.status_code == 400


def test_vertical_crs_not_offered(client: FlaskClient) -> None:
# A height-only CRS cannot place X and Y
vertical = {"authority": "EPSG", "code": "7839", "name": "NZVD2016 height"}
response = client.post(
"/opengeodeweb_back/crs/geographic_list", json={"geode_object_type": "PointSet3D"}
)
codes = {(crs["authority"], crs["code"]) for crs in response.get_json()["crs_list"]}
assert ("EPSG", "7839") not in codes
assert ("EPSG", "2193") in codes
[point_set] = test_utils.check_save_viewable_file(client, "PointSet3D", "test.og_pts3d")
response = client.post(
"/opengeodeweb_back/crs/assign_geographic", json={"id": point_set["id"], **vertical}
)
assert response.status_code == 400


def test_assign_only_rewrites_the_native_file(client: FlaskClient) -> None:
[point_set] = test_utils.check_save_viewable_file(client, "PointSet3D", "test.og_pts3d")
point_set_id = point_set["id"]
Expand Down Expand Up @@ -637,6 +653,16 @@ def test_assign_only_plausible(client: FlaskClient) -> None:
assert _active_crs(client, plausible_id) == LAMBERT


def test_assign_geographic_model_without_block_meshes(client: FlaskClient) -> None:
route = "/opengeodeweb_back/crs/assign_geographic"
# Models built from surfaces often keep their blocks without mesh
[brep] = test_utils.check_save_viewable_file(client, "BRep", "corbi.og_brep")
response = client.post(route, json={"id": brep["id"], **LAMBERT})
assert response.status_code == 200
assert response.get_json()["crs"] == LAMBERT
assert _active_crs(client, brep["id"]) == LAMBERT


def test_assign_linked(client: FlaskClient) -> None:
route = "/opengeodeweb_back/crs/assign_geographic"
point_set_id = _create_point_set(client)
Expand Down
Loading