Skip to content

Commit

Permalink
Fix platforms_split view causing NULL IFOPTs
Browse files Browse the repository at this point in the history
The problem occurred whenever the ref tag contained more values than the IFOPT tag
  • Loading branch information
Robbendebiene committed Apr 19, 2024
1 parent a783a44 commit 3f00183
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions pipeline/stop_places/sql/stop_places.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1047,25 +1047,29 @@ CREATE OR REPLACE VIEW platforms_split AS (
ps.osm_type as osm_type,
ps.osm_id as osm_id,
-- Get the corresponding IFOPT by using the split IFOPT from the subquery 'ps'
ps."split_IFOPT" as "IFOPT",
"split_IFOPT" as "IFOPT",
COALESCE(jsonb_concat(ps.tags, pe.tags), ps.tags) as tags,
COALESCE(pe.geom, ps.geom) as geom
FROM (
-- split platforms with multiple IFOPTs and expand into multiple rows
-- if there is only one IFOPT the original IFOPT is put into 'split_IFOPT'
-- 'split_ref' will be NULL if thre is no ref tag
SELECT
*,
string_to_table(pww."IFOPT", ';') AS "split_IFOPT",
string_to_table(pww.tags->>'ref', ';') AS "split_ref"
-- "refs" will be NULL if there is no ref tag
-- do not cross join string_to_table(pww.tags->>'ref', ';'), because sometimes ref is used for different things (like bus routes serving a stop)
-- i.e. it is not guaranteed that we will always have the exact number of refs as IFOPTs
-- therefore we only split the rows on the IFOPTs otherwise we can have rows where IFOPT will be NULL
string_to_array(pww.tags->>'ref', ';') AS refs
FROM platforms_with_width AS pww
-- split platforms with multiple IFOPTs and expand into multiple rows
-- if there is only one IFOPT the original IFOPT is put into 'split_IFOPT'
-- additionally the index/ordinality is stored to later access the respective "ref" value
CROSS JOIN string_to_table(pww."IFOPT", ';') WITH ORDINALITY AS _("split_IFOPT", index)
) ps
-- Join platform edges if any to the platforms to refine tags and geometry
LEFT JOIN platforms_edges pe
-- Check if the platform edge fully overlaps with the platform border
ON ST_Touches(ps.geom, pe.geom) AND
-- Only use the platform edges that have the same ref tag as the platform
ps."split_ref" = pe.tags->>'ref'
-- Check if the platform edge fully overlaps with the platform border
ON ST_Touches(ps.geom, pe.geom) AND
-- Only use the platform edges that have the same ref tag as the platform
refs[ps.index] = pe.tags->>'ref'
);


Expand Down

0 comments on commit 3f00183

Please sign in to comment.