Skip to content

Commit

Permalink
editoast: better sql query to split a track section
Browse files Browse the repository at this point in the history
Fix #8947

New query is not using the `ST_LineSubstring` which gives bad result with geography data that has long segment.
By computing the geo point and doing a split of the TS near this point, it's a lot better.

Signed-off-by: Benoit Simard <contact@bsimard.com>
  • Loading branch information
sim51 committed Jan 2, 2025
1 parent 04792ff commit e2fac0f
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions editoast/src/models/infra/sql/get_split_track_section_with_data.sql
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
SELECT object_table.obj_id as obj_id,
object_table.data as railjson,
ST_AsGeoJSON(
ST_Transform(
ST_LineSubstring(
layer_table.geographic,
0,
$3
SELECT
obj_id,
railjson,
ST_AsGeoJSON( ST_Transform(ST_GeometryN( splitted, 1 ), 4326) )::jsonb as left_geo,
ST_AsGeoJSON( ST_Transform(ST_GeometryN( splitted, 2 ), 4326) )::jsonb as right_geo
FROM (
SELECT
obj_id,
railjson,
ST_SPLIT(
ST_Snap(
geometry::geometry,
geo_split_point::geometry,
ST_Distance(geometry::geometry, geo_split_point::geometry)*1.01
),
4326
geo_split_point::geometry
) as splitted
FROM
(SELECT
object_table.obj_id as obj_id,
object_table.data as railjson,
ST_Transform(layer_table.geographic, 4326)::geography as geometry,
ST_LineInterpolatePoint(
ST_Transform(layer_table.geographic, 4326),
$3::float,
True
) as geo_split_point
FROM infra_object_track_section AS object_table
LEFT JOIN infra_layer_track_section AS layer_table ON layer_table.infra_id = object_table.infra_id
AND object_table.obj_id = layer_table.obj_id
WHERE object_table.infra_id = $1
AND object_table.obj_id = $2
)
)::jsonb as left_geo,
ST_AsGeoJSON(
ST_Transform(
ST_LineSubstring(
layer_table.geographic,
$3,
1
),
4326
)
)::jsonb as right_geo
FROM infra_object_track_section AS object_table
LEFT JOIN infra_layer_track_section AS layer_table ON layer_table.infra_id = object_table.infra_id
AND object_table.obj_id = layer_table.obj_id
WHERE object_table.infra_id = $1
AND object_table.obj_id = $2
);

0 comments on commit e2fac0f

Please sign in to comment.