Skip to content

Commit

Permalink
editoast: add new track_section field in operational point layer
Browse files Browse the repository at this point in the history
Signed-off-by: Youness CHRIFI ALAOUI <youness.chrifi@gmail.com>
  • Loading branch information
younesschrifi committed Nov 27, 2024
1 parent 5ec5bf4 commit 8078784
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 7 deletions.
1 change: 1 addition & 0 deletions editoast/editoast_models/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ diesel::table! {
geographic -> Geometry,
infra_id -> Int8,
kp -> Nullable<Text>,
track_section -> Text,
}
}

Expand Down
3 changes: 2 additions & 1 deletion editoast/map_layers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ layers:
views:
geo:
on_field: geographic
data_expr: operational_point.data - 'parts' || jsonb_build_object('kp', layer.kp)
data_expr: operational_point.data - 'parts' || jsonb_build_object('kp', layer.kp, 'track_id', layer.track_section, 'track_label', track_section.data->'extensions'->'sncf'->'track_name')
joins:
- inner join infra_object_operational_point operational_point on operational_point.obj_id = layer.obj_id and operational_point.infra_id = layer.infra_id
- inner join infra_object_track_section track_section on track_section.obj_id = layer.track_section and track_section.infra_id = layer.infra_id

electrifications:
table_name: infra_layer_electrification
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE infra_layer_operational_point DROP COLUMN track_section;
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
DELETE FROM infra_layer_operational_point;
ALTER TABLE infra_layer_operational_point ADD COLUMN track_section text NOT NULL;

WITH ops AS (
SELECT obj_id AS op_id,
infra_id,
(
jsonb_array_elements(data->'parts')->'position'
)::float AS position,
jsonb_array_elements(data->'parts')->>'track' AS track_id,
jsonb_array_elements(data->'parts')->'extensions'->'sncf'->>'kp' AS kp
FROM infra_object_operational_point
),
collect AS (
SELECT ops.op_id,
ST_LineInterpolatePoint(
tracks_layer.geographic,
LEAST(
GREATEST(
ops.position / (tracks.data->'length')::float,
0.
),
1.
)
) AS geo,
ops.kp AS kp,
ops.infra_id AS infra_id,
ops.track_id AS track_section
FROM ops
INNER JOIN infra_object_track_section AS tracks ON tracks.obj_id = ops.track_id AND tracks.infra_id = ops.infra_id
INNER JOIN infra_layer_track_section AS tracks_layer ON tracks.obj_id = tracks_layer.obj_id
AND tracks.infra_id = tracks_layer.infra_id
)
INSERT INTO infra_layer_operational_point (obj_id, infra_id, geographic, kp, track_section)
SELECT op_id,
infra_id,
geo,
kp,
track_section
FROM collect;
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ collect AS (
1.
)
) AS geo,
ops.kp AS kp
ops.kp AS kp,
ops.track_id AS track_section
FROM ops
INNER JOIN infra_object_track_section AS tracks ON tracks.obj_id = ops.track_id
AND tracks.infra_id = $1
INNER JOIN infra_layer_track_section AS tracks_layer ON tracks.obj_id = tracks_layer.obj_id
AND tracks.infra_id = tracks_layer.infra_id
)
INSERT INTO infra_layer_operational_point (obj_id, infra_id, geographic, kp)
INSERT INTO infra_layer_operational_point (obj_id, infra_id, geographic, kp, track_section)
SELECT op_id,
$1,
geo,
kp
kp,
track_section
FROM collect
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ collect AS (
1.
)
) AS geo,
ops.kp AS kp
ops.kp AS kp,
ops.track_id AS track_section
FROM ops
INNER JOIN infra_object_track_section AS tracks ON tracks.obj_id = ops.track_id
AND tracks.infra_id = $1
INNER JOIN infra_layer_track_section AS tracks_layer ON tracks.obj_id = tracks_layer.obj_id
AND tracks.infra_id = tracks_layer.infra_id
)
INSERT INTO infra_layer_operational_point (obj_id, infra_id, geographic, kp)
INSERT INTO infra_layer_operational_point (obj_id, infra_id, geographic, kp, track_section)
SELECT op_id,
$1,
geo,
kp
kp,
track_section
FROM collect

0 comments on commit 8078784

Please sign in to comment.