Files
TJWaterServerBinary/app/infra/db/postgresql/project_spatial.py
jiang 90b02057bc
Generic Container CI/CD / test-build-publish (push) Successful in 1m13s
Server CI/CD v2 / build-test-publish-and-deploy (push) Successful in 1m13s
feat(projects): automate project infrastructure provisioning
2026-09-11 10:57:51 +08:00

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"))