Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1091 by properly filtering one-way streets #1092

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gis/centreline/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
21 changes: 13 additions & 8 deletions gis/centreline/sql/create_view_routing_centreline_directional.sql
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
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_length,
geom

FROM (
SELECT
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
0 AS dir
FROM gis_core.centreline_latest AS centreline
WHERE centreline.oneway_dir_code >= 0 -- bi-directional and with digitization

UNION

SELECT
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
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;
Expand Down