-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
editoast: better sql query to split a track section
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
Showing
1 changed file
with
33 additions
and
25 deletions.
There are no files selected for viewing
58 changes: 33 additions & 25 deletions
58
editoast/src/models/infra/sql/get_split_track_section_with_data.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,35 @@ | ||
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) | ||
), | ||
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 | ||
); |