31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from app.native.wndb.core.connection import project_connection
|
|
|
|
|
|
def get_project_map_bbox(project: str) -> tuple[float, float, float, float]:
|
|
"""Return the combined published node/link bounds in EPSG:3857."""
|
|
with project_connection(project) as conn, conn.cursor() as cur:
|
|
cur.execute(
|
|
"""
|
|
with project_geometries as (
|
|
select geom from gis.junctions
|
|
union all
|
|
select geom from gis.pipes
|
|
), bounds as (
|
|
select ST_Extent(geom) as extent from project_geometries
|
|
)
|
|
select ST_XMin(extent) as minx,
|
|
ST_YMin(extent) as miny,
|
|
ST_XMax(extent) as maxx,
|
|
ST_YMax(extent) as maxy
|
|
from bounds
|
|
"""
|
|
)
|
|
row = cur.fetchone()
|
|
if row is None or any(
|
|
row[key] is None for key in ("minx", "miny", "maxx", "maxy")
|
|
):
|
|
raise RuntimeError("Imported model has no publishable GIS geometry")
|
|
return tuple(float(row[key]) for key in ("minx", "miny", "maxx", "maxy"))
|