diff --git a/requirements.txt b/requirements.txt index 5c24d6ce..597e5178 100644 --- a/requirements.txt +++ b/requirements.txt @@ -84,4 +84,3 @@ werkzeug==3.1.8 # flask # flask-cors -opengeodeweb-microservice==1.*,>=1.4.0 diff --git a/src/opengeodeweb_back/crs/crs_functions.py b/src/opengeodeweb_back/crs/crs_functions.py index c02de0ec..dd9a2f01 100644 --- a/src/opengeodeweb_back/crs/crs_functions.py +++ b/src/opengeodeweb_back/crs/crs_functions.py @@ -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( @@ -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], @@ -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), diff --git a/tests/test_crs_routes.py b/tests/test_crs_routes.py index 6599a01d..550abe41 100644 --- a/tests/test_crs_routes.py +++ b/tests/test_crs_routes.py @@ -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"] @@ -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)