Skip to content

Commit

Permalink
ensure control_measure_map.geom is a valid line
Browse files Browse the repository at this point in the history
  • Loading branch information
margrietpalm committed Sep 25, 2024
1 parent e37f006 commit 4a4eb7a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog of threedi-schema

- Swap start and end of control_measure_map geometries
- Modify geometry of controls associated with pumpstation to the pumpstation start node
- Ensure control_measure_map.geom is a valid line


0.224.6 (2024-09-25)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,41 @@ def add_control_geometries(control_name):
op.execute(sa.text(query))


def get_global_srid():
conn = op.get_bind()
use_0d_inflow = conn.execute(sa.text("SELECT use_0d_inflow FROM simulation_template_settings LIMIT 1")).fetchone()
if use_0d_inflow is not None:
srid = conn.execute(sa.text("SELECT epsg_code FROM model_settings LIMIT 1")).fetchone()
if (srid is not None) and (srid[0] is not None):
return srid[0]
return 28992


def set_geom_for_control_measure_map():
srid = get_global_srid()
for control in ['memory', 'table']:
control_table = f'{control}_control'
query = f"""
UPDATE
control_measure_map
SET
geom = (
SELECT
MakeLine(cml.geom, tc.geom)
SELECT CASE
WHEN ST_Equals(cml.geom, tc.geom) THEN
-- Transform to EPSG:4326 for the projection, then back to the original SRID
MakeLine(
cml.geom,
PointOnSurface(ST_Transform(
ST_Translate(
ST_Transform(tc.geom, {srid}),
0, 1, 0
),
4326
))
)
ELSE
MakeLine(cml.geom, tc.geom)
END
FROM
{control_table} AS tc
JOIN
Expand Down

0 comments on commit 4a4eb7a

Please sign in to comment.