diff --git a/layers/transportation/network_type.sql b/layers/transportation/network_type.sql index b54dc8d6..7e384a37 100644 --- a/layers/transportation/network_type.sql +++ b/layers/transportation/network_type.sql @@ -15,12 +15,23 @@ $$ WHEN undefined_object THEN CREATE TYPE route_network_type AS enum ( 'us-interstate', 'us-highway', 'us-state', - 'ca-transcanada', + 'ca-transcanada', 'ca-provincial-arterial', 'ca-provincial', 'gb-motorway', 'gb-trunk' ); END $$; +-- Top-level national route networks that should display at the lowest zooms +CREATE OR REPLACE FUNCTION osm_national_network(network text) RETURNS boolean AS +$$ + SELECT network <> '' AND network IN ( + -- Canada + 'ca-transcanada', 'ca-provincial-arterial', + -- United States + 'us-interstate'); +$$ LANGUAGE sql IMMUTABLE + PARALLEL SAFE; + DO $$ BEGIN diff --git a/layers/transportation/update_route_member.sql b/layers/transportation/update_route_member.sql index 3a624029..de73c2a1 100644 --- a/layers/transportation/update_route_member.sql +++ b/layers/transportation/update_route_member.sql @@ -22,7 +22,7 @@ INSERT INTO osm_route_member (osm_id, member, ref, network) SELECT * FROM gbr_route_members_view; -CREATE OR REPLACE FUNCTION osm_route_member_network_type(network text) RETURNS route_network_type AS +CREATE OR REPLACE FUNCTION osm_route_member_network_type(network text, ref text) RETURNS route_network_type AS $$ SELECT CASE WHEN network = 'US:I' THEN 'us-interstate'::route_network_type @@ -30,6 +30,17 @@ SELECT CASE WHEN network LIKE 'US:__' THEN 'us-state'::route_network_type -- https://en.wikipedia.org/wiki/Trans-Canada_Highway WHEN network LIKE 'CA:transcanada%' THEN 'ca-transcanada'::route_network_type + WHEN network = 'CA:QC:A' THEN 'ca-provincial-arterial'::route_network_type + WHEN network = 'CA:ON:primary' THEN + CASE + WHEN ref LIKE '4__' THEN 'ca-provincial-arterial'::route_network_type + WHEN ref = 'QEW' THEN 'ca-provincial-arterial'::route_network_type + ELSE 'ca-provincial-arterial'::route_network_type + END + WHEN network = 'CA:MB:PTH' AND ref = '75' THEN 'ca-provincial-arterial'::route_network_type + WHEN network = 'CA:AB:primary' AND ref IN ('2','3','4') THEN 'ca-provincial-arterial'::route_network_type + WHEN network = 'CA:BC' AND ref IN ('3','5','99') THEN 'ca-provincial-arterial'::route_network_type + WHEN network LIKE 'CA:__' OR network LIKE 'CA:__:%' THEN 'ca-provincial'::route_network_type WHEN network = 'omt-gb-motorway' THEN 'gb-motorway'::route_network_type WHEN network = 'omt-gb-trunk' THEN 'gb-trunk'::route_network_type END; @@ -39,9 +50,9 @@ $$ LANGUAGE sql IMMUTABLE -- etldoc: osm_route_member -> osm_route_member -- see http://wiki.openstreetmap.org/wiki/Relation:route#Road_routes UPDATE osm_route_member -SET network_type = osm_route_member_network_type(network) +SET network_type = osm_route_member_network_type(network, ref) WHERE network != '' - AND network_type IS DISTINCT FROM osm_route_member_network_type(network) + AND network_type IS DISTINCT FROM osm_route_member_network_type(network, ref) ; CREATE OR REPLACE FUNCTION update_osm_route_member() RETURNS void AS @@ -64,7 +75,7 @@ BEGIN SELECT id, osm_id, - osm_route_member_network_type(network) AS network_type, + osm_route_member_network_type(network, ref) AS network_type, DENSE_RANK() over (PARTITION BY member ORDER BY network_type, network, LENGTH(ref), ref) AS concurrency_index, CASE WHEN network IN ('iwn', 'nwn', 'rwn') THEN 1 @@ -80,7 +91,7 @@ BEGIN END; $$ LANGUAGE plpgsql; -CREATE INDEX IF NOT EXISTS osm_route_member_network_idx ON osm_route_member ("network"); +CREATE INDEX IF NOT EXISTS osm_route_member_network_idx ON osm_route_member ("network", "ref"); CREATE INDEX IF NOT EXISTS osm_route_member_member_idx ON osm_route_member ("member"); CREATE INDEX IF NOT EXISTS osm_route_member_name_idx ON osm_route_member ("name"); CREATE INDEX IF NOT EXISTS osm_route_member_ref_idx ON osm_route_member ("ref"); diff --git a/layers/transportation/update_transportation_merge.sql b/layers/transportation/update_transportation_merge.sql index 9f048a46..dcf12a50 100644 --- a/layers/transportation/update_transportation_merge.sql +++ b/layers/transportation/update_transportation_merge.sql @@ -331,9 +331,7 @@ BEGIN (highway = 'motorway' OR construction = 'motorway' -- Allow trunk roads that are part of a nation's most important route network to show at z4 - OR highway = 'trunk' AND - network <> '' AND - network IN ('ca-transcanada','us-interstate') + OR (highway = 'trunk' AND osm_national_network(network)) ) AND ST_Length(geometry) > 500; @@ -356,8 +354,8 @@ BEGIN FROM osm_transportation_merge_linestring_gen_z5 WHERE (update_id IS NULL OR id = update_id) AND + osm_national_network(network) AND -- Current view: national-importance motorways and trunks - network IN ('ca-transcanada','us-interstate') AND ST_Length(geometry) > 1000; END; $$ LANGUAGE plpgsql; diff --git a/layers/transportation_name/transportation_name.yaml b/layers/transportation_name/transportation_name.yaml index 790fc421..b08f1193 100644 --- a/layers/transportation_name/transportation_name.yaml +++ b/layers/transportation_name/transportation_name.yaml @@ -28,6 +28,8 @@ layer: - us-highway - us-state - ca-transcanada + - ca-provincial-arterial + - ca-provincial - gb-motorway - gb-trunk - road (default)