From 255623b5137629390d1c009ed62e46c3a47932fc Mon Sep 17 00:00:00 2001 From: Raphael Dumas Date: Fri, 1 Nov 2024 18:25:34 -0400 Subject: [PATCH 1/4] Fix #1091 by properly filtering one-way streets The flow of traffic is opposite the drawn direction for one way streets that are -1 --- .../sql/create_view_routing_centreline_directional.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gis/centreline/sql/create_view_routing_centreline_directional.sql b/gis/centreline/sql/create_view_routing_centreline_directional.sql index 4deac9845..73f13374a 100644 --- a/gis/centreline/sql/create_view_routing_centreline_directional.sql +++ b/gis/centreline/sql/create_view_routing_centreline_directional.sql @@ -17,6 +17,7 @@ FROM ( centreline.geom, 0 as dir FROM gis_core.centreline_latest AS centreline + WHERE centreline.oneway_dir_code >= 0 -- bi-directional and with digitization UNION @@ -28,12 +29,13 @@ FROM ( st_reverse(centreline.geom) AS geom, 1 as dir FROM gis_core.centreline_latest AS centreline - WHERE centreline.oneway_dir_code = 0) AS dup; + WHERE centreline.oneway_dir_code <= 0 /*bi-directional or against digitization*/ + ) AS dup; ALTER TABLE gis_core.routing_centreline_directional OWNER TO gis_admins; COMMENT ON VIEW gis_core.routing_centreline_directional -IS 'A view that contains centreline streets for routing, with duplicated rows for two-way streets and flipped geometries when necessary. A new id has been assigned to each centreline to distinguish duplicated lines.'; +IS 'A view that contains centreline streets for routing, with duplicated rows for two-way streets and flipped geometries when lines were drawn against digitization. A new id has been assigned to each centreline to distinguish duplicated lines.'; GRANT SELECT ON TABLE gis_core.routing_centreline_directional TO bdit_humans; GRANT ALL ON TABLE gis_core.routing_centreline_directional TO gis_admins; From 363d5fe3cfd4541d19d2e2d0802c04bab9ff4624 Mon Sep 17 00:00:00 2001 From: radumas Date: Fri, 22 Nov 2024 21:08:18 +0000 Subject: [PATCH 2/4] #1091 :meow_fluffy: --- ...te_view_routing_centreline_directional.sql | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/gis/centreline/sql/create_view_routing_centreline_directional.sql b/gis/centreline/sql/create_view_routing_centreline_directional.sql index 73f13374a..cb8a221d1 100644 --- a/gis/centreline/sql/create_view_routing_centreline_directional.sql +++ b/gis/centreline/sql/create_view_routing_centreline_directional.sql @@ -1,11 +1,11 @@ CREATE OR REPLACE VIEW gis_core.routing_centreline_directional AS -SELECT +SELECT centreline_id, concat(row_number() OVER (), dir)::bigint AS id, source, target, - cost, + "cost", geom FROM ( @@ -13,9 +13,9 @@ FROM ( centreline.centreline_id, centreline.from_intersection_id AS source, centreline.to_intersection_id AS target, - centreline.shape_length AS cost, + centreline.shape_length AS "cost", centreline.geom, - 0 as dir + 0 AS dir FROM gis_core.centreline_latest AS centreline WHERE centreline.oneway_dir_code >= 0 -- bi-directional and with digitization @@ -25,17 +25,20 @@ FROM ( centreline.centreline_id, centreline.to_intersection_id AS source, centreline.from_intersection_id AS target, - centreline.shape_length AS cost, + centreline.shape_length AS "cost", st_reverse(centreline.geom) AS geom, - 1 as dir + 1 AS dir FROM gis_core.centreline_latest AS centreline WHERE centreline.oneway_dir_code <= 0 /*bi-directional or against digitization*/ - ) AS dup; +) AS dup; ALTER TABLE gis_core.routing_centreline_directional OWNER TO gis_admins; COMMENT ON VIEW gis_core.routing_centreline_directional -IS 'A view that contains centreline streets for routing, with duplicated rows for two-way streets and flipped geometries when lines were drawn against digitization. A new id has been assigned to each centreline to distinguish duplicated lines.'; +IS '''A view that contains centreline streets for routing, with duplicated rows +for two-way streets and flipped geometries when lines were drawn against +digitization. A new id has been assigned to each centreline to distinguish +duplicated lines.'''; GRANT SELECT ON TABLE gis_core.routing_centreline_directional TO bdit_humans; GRANT ALL ON TABLE gis_core.routing_centreline_directional TO gis_admins; From 401b132ffc4df3c0444f4220b49484724347c213 Mon Sep 17 00:00:00 2001 From: radumas Date: Fri, 22 Nov 2024 21:16:55 +0000 Subject: [PATCH 3/4] #1091 cost_length, add a lil documentation --- gis/centreline/readme.md | 4 ++-- .../sql/create_view_routing_centreline_directional.sql | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gis/centreline/readme.md b/gis/centreline/readme.md index 12278ca18..3987655bb 100644 --- a/gis/centreline/readme.md +++ b/gis/centreline/readme.md @@ -14,7 +14,7 @@ The centreline data are used by many other groups in the City and it's often imp ## How It's Structured -* The `gis_core.centreline_latest` Materialized View contains the latest set of lines with unique id `centreline_id`. These lines are undirected. All edges have _from_ and _to_ nodes, though this should not be taken to indicate that edges are directed. For a directed centreline layer, check out `gis_core.routing_centreline_directional` ([see more](#centreline-segments-edges)) +* The `gis_core.centreline_latest` Materialized View contains the latest set of lines with unique id `centreline_id`. These lines are undirected. All edges have _from_ and _to_ nodes, though this should not be taken to indicate that edges are directed. For a directed centreline layer, check out `gis_core.routing_centreline_directional` ([see more](#centreline-segments-edges)) which has the necessary schema to be used in pg_routing. * The `centreline_intersection_point_latest` Materialized View contains the latest set of unique intersections with unique id `intersection_id`. These are any location where two lines intersect, not strictly intersections in the transportation sense ([see more](#intersections-nodes)) ## Where It's Stored @@ -41,7 +41,7 @@ Currently we are including only the following types: #### Directionality -Directionality of streets can be identified with the column `oneway_dir_code_desc`, distinguishing whether the segment is a one-way street. A two way street will be represented by a single segment. `oneway_dir_code` can be used to identify whether a segment is being drawn with the digitization or against, indicating vehicular traffic direction. +Directionality of streets can be identified with the column `oneway_dir_code_desc`, distinguishing whether the segment is a one-way street. A two way street will be represented by a single segment (`oneway_dir_code = 0`). `oneway_dir_code` can be used to identify whether a segment is being drawn with the digitization (1) or against (-1), indicating vehicular traffic direction. #### Lineage diff --git a/gis/centreline/sql/create_view_routing_centreline_directional.sql b/gis/centreline/sql/create_view_routing_centreline_directional.sql index cb8a221d1..bc5bd3068 100644 --- a/gis/centreline/sql/create_view_routing_centreline_directional.sql +++ b/gis/centreline/sql/create_view_routing_centreline_directional.sql @@ -5,7 +5,7 @@ SELECT concat(row_number() OVER (), dir)::bigint AS id, source, target, - "cost", + cost_length, geom FROM ( @@ -13,7 +13,7 @@ FROM ( centreline.centreline_id, centreline.from_intersection_id AS source, centreline.to_intersection_id AS target, - centreline.shape_length AS "cost", + centreline.shape_length AS cost_length, centreline.geom, 0 AS dir FROM gis_core.centreline_latest AS centreline @@ -25,7 +25,7 @@ FROM ( centreline.centreline_id, centreline.to_intersection_id AS source, centreline.from_intersection_id AS target, - centreline.shape_length AS "cost", + centreline.shape_length AS cost_length, st_reverse(centreline.geom) AS geom, 1 AS dir FROM gis_core.centreline_latest AS centreline From 15d3d7710466c30a07d0c9ebecd2e553fdc17bec Mon Sep 17 00:00:00 2001 From: Raphael Dumas Date: Fri, 6 Dec 2024 16:15:13 -0500 Subject: [PATCH 4/4] fix routing function bug introduced by #1092 --- .../sql/create_function_get_centreline_btwn_intersections.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gis/centreline/sql/create_function_get_centreline_btwn_intersections.sql b/gis/centreline/sql/create_function_get_centreline_btwn_intersections.sql index 0c8236171..c0cd6aaa3 100644 --- a/gis/centreline/sql/create_function_get_centreline_btwn_intersections.sql +++ b/gis/centreline/sql/create_function_get_centreline_btwn_intersections.sql @@ -15,7 +15,7 @@ AS $BODY$ WITH results as ( SELECT * - FROM pgr_dijkstra('SELECT id, source::int, target::int, cost::int + FROM pgr_dijkstra('SELECT id, source::int, target::int, cost_length::int as cost from gis_core.routing_centreline_directional', _node_start, _node_end) )