Skip to content

Commit

Permalink
#884 add functions and view for routing centreline
Browse files Browse the repository at this point in the history
  • Loading branch information
chmnata authored and radumas committed Apr 22, 2024
1 parent b1d61be commit 2c0cd74
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
CREATE OR REPLACE FUNCTION gis_core.get_centreline_btwn_intersections(
_node_start integer,
_node_end integer,
OUT _node_start_out integer,
OUT _node_end integer,
OUT links text[],
OUT geom geometry)
RETURNS record
LANGUAGE 'sql'
COST 100
STABLE STRICT PARALLEL UNSAFE
AS $BODY$
WITH results as (
SELECT *
FROM pgr_dijkstra('SELECT id, source::int, target::int, cost::int
as cost from gis_core.routing_centreline_directional', _node_start, _node_end)
)

SELECT _node_start, _node_end, array_agg(centreline_id), ST_union(ST_linemerge(geom)) as geom
from results
inner join gis_core.routing_centreline_directional on edge=id

$BODY$;

ALTER FUNCTION gis_core.get_centreline_btwn_intersections(integer, integer)
OWNER TO gis_admins;

COMMENT ON FUNCTION gis_core.get_centreline_btwn_intersections(integer, integer)
IS 'Routing function for centreline, takes in start intersection_id and end intersection_id and returns an array of centreline_id, as well as one line geometry between two intersections.';

GRANT EXECUTE ON FUNCTION gis_core.get_centreline_btwn_intersections(integer, integer) TO bdit_humans;

GRANT EXECUTE ON FUNCTION gis_core.get_centreline_btwn_intersections(integer, integer) TO gis_admins;

34 changes: 34 additions & 0 deletions gis/centreline/sql/create_view_routing_centreline_directional.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
CREATE OR REPLACE VIEW gis_core.routing_centreline_directional AS

SELECT
centreline.centreline_id,
concat(centreline.centreline_id, 0)::integer AS id,
centreline.from_intersection_id AS source,
centreline.to_intersection_id AS target,
centreline.shape_length AS cost,
centreline.geom
FROM gis_core.centreline_latest centreline

UNION

SELECT
centreline.centreline_id,
concat(centreline.centreline_id, 1)::integer AS id,
centreline.to_intersection_id AS source,
centreline.from_intersection_id AS target,
centreline.shape_length AS cost,
st_reverse(centreline.geom) AS geom
FROM gis_core.centreline_latest centreline
WHERE centreline.oneway_dir_code = 0;

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.';

GRANT SELECT ON TABLE gis_core.routing_centreline_directional TO bdit_humans;
GRANT ALL ON TABLE gis_core.routing_centreline_directional TO gis_admins;



0 comments on commit 2c0cd74

Please sign in to comment.