File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
threedi_schema/migrations/versions Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ Changelog of threedi-schema
7
7
8
8
- Swap start and end of control_measure_map geometries
9
9
- Modify geometry of controls associated with pumpstation to the pumpstation start node
10
+ - Ensure control_measure_map.geom is a valid line
10
11
11
12
12
13
0.224.6 (2024-09-25)
Original file line number Diff line number Diff line change @@ -196,16 +196,41 @@ def add_control_geometries(control_name):
196
196
op .execute (sa .text (query ))
197
197
198
198
199
+ def get_global_srid ():
200
+ conn = op .get_bind ()
201
+ use_0d_inflow = conn .execute (sa .text ("SELECT use_0d_inflow FROM simulation_template_settings LIMIT 1" )).fetchone ()
202
+ if use_0d_inflow is not None :
203
+ srid = conn .execute (sa .text ("SELECT epsg_code FROM model_settings LIMIT 1" )).fetchone ()
204
+ if (srid is not None ) and (srid [0 ] is not None ):
205
+ return srid [0 ]
206
+ return 28992
207
+
208
+
199
209
def set_geom_for_control_measure_map ():
210
+ srid = get_global_srid ()
200
211
for control in ['memory' , 'table' ]:
201
212
control_table = f'{ control } _control'
202
213
query = f"""
203
214
UPDATE
204
215
control_measure_map
205
216
SET
206
217
geom = (
207
- SELECT
208
- MakeLine(cml.geom, tc.geom)
218
+ SELECT CASE
219
+ WHEN ST_Equals(cml.geom, tc.geom) THEN
220
+ -- Transform to EPSG:4326 for the projection, then back to the original SRID
221
+ MakeLine(
222
+ cml.geom,
223
+ PointOnSurface(ST_Transform(
224
+ ST_Translate(
225
+ ST_Transform(tc.geom, { srid } ),
226
+ 0, 1, 0
227
+ ),
228
+ 4326
229
+ ))
230
+ )
231
+ ELSE
232
+ MakeLine(cml.geom, tc.geom)
233
+ END
209
234
FROM
210
235
{ control_table } AS tc
211
236
JOIN
You can’t perform that action at this time.
0 commit comments