Add network to transport layer (#1158)
Closes #1153 This PR populates the existing `network_type` field in the route table with highway route network information, using the most important value in cases of concurrencies. In order to expose this value, two files `network_type.sql` and `update_route_member.sql` were moved from the `transportation_name` layer to the `transportation` layer. Below is a representative zoom level 6 with motorways only shown for `us-interstate` network types. This sample was generated from this PR using a [custom branch](https://github.com/ZeLonewolf/openstreetmap-americana/tree/selective-highway-zoom) of openstreetmap-americana. This provides a simplified rendering of the highway network which excludes many minor motorway roads and sections.  Below is zoom level 6 on the current [openstreetmap-americana](https://zelonewolf.github.io/openstreetmap-americana/#6/42.148/-73.712). Notice the many additional stubs, motorway islands, and minor routes which are present. Instead of rendering `highway=trunk` to make this network look nice, we can instead suppress non-interstate roads and withhold motorway+trunk rendering to a closer zoom: 
This commit is contained in:
committed by
GitHub
parent
9e4be3e3b0
commit
08bb2a06c0
Binary file not shown.
|
Before Width: | Height: | Size: 232 KiB After Width: | Height: | Size: 258 KiB |
@@ -1,33 +0,0 @@
|
||||
DROP TRIGGER IF EXISTS trigger_store_transportation_route_member ON osm_route_member;
|
||||
DROP TRIGGER IF EXISTS trigger_store_transportation_highway_linestring ON osm_highway_linestring;
|
||||
DROP TRIGGER IF EXISTS trigger_flag_transportation_name ON transportation_name.network_changes;
|
||||
DROP TRIGGER IF EXISTS trigger_refresh_network ON transportation_name.updates_network;
|
||||
|
||||
DROP TRIGGER IF EXISTS trigger_store_transportation_name_network ON osm_transportation_name_network;
|
||||
DROP TRIGGER IF EXISTS trigger_flag_name ON transportation_name.name_changes;
|
||||
DROP TRIGGER IF EXISTS trigger_refresh_name ON transportation_name.updates_name;
|
||||
|
||||
DO
|
||||
$$
|
||||
BEGIN
|
||||
IF NOT EXISTS(SELECT 1 FROM pg_type WHERE typname = 'route_network_type') THEN
|
||||
CREATE TYPE route_network_type AS enum (
|
||||
'us-interstate', 'us-highway', 'us-state',
|
||||
'ca-transcanada',
|
||||
'gb-motorway', 'gb-trunk'
|
||||
);
|
||||
END IF;
|
||||
END
|
||||
$$;
|
||||
|
||||
DO
|
||||
$$
|
||||
BEGIN
|
||||
BEGIN
|
||||
ALTER TABLE osm_route_member
|
||||
ADD COLUMN network_type route_network_type;
|
||||
EXCEPTION
|
||||
WHEN duplicate_column THEN RAISE NOTICE 'column network_type already exists in network_type.';
|
||||
END;
|
||||
END;
|
||||
$$;
|
||||
@@ -184,7 +184,6 @@ FROM (
|
||||
NULL::boolean AS indoor
|
||||
FROM osm_highway_point p
|
||||
WHERE highway = 'motorway_junction' AND zoom_level >= 10
|
||||
|
||||
) AS zoom_levels
|
||||
WHERE geometry && bbox
|
||||
ORDER BY z_order ASC;
|
||||
|
||||
@@ -104,9 +104,7 @@ layer:
|
||||
srid: 900913
|
||||
query: (SELECT geometry, name, name_en, name_de, {name_languages}, ref, ref_length, network::text, class::text, subclass, brunnel, layer, level, indoor, route_1, route_2, route_3, route_4, route_5, route_6 FROM layer_transportation_name(!bbox!, z(!scale_denominator!))) AS t
|
||||
schema:
|
||||
- ./network_type.sql
|
||||
- ./highway_classification.sql
|
||||
- ./update_route_member.sql
|
||||
- ./update_transportation_name.sql
|
||||
- ./transportation_name.sql
|
||||
datasources:
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
CREATE TABLE IF NOT EXISTS ne_10m_admin_0_bg_buffer AS
|
||||
SELECT ST_Buffer(geometry, 10000)
|
||||
FROM ne_10m_admin_0_countries
|
||||
WHERE iso_a2 = 'GB';
|
||||
|
||||
CREATE OR REPLACE VIEW gbr_route_members_view AS
|
||||
SELECT 0,
|
||||
osm_id,
|
||||
substring(ref FROM E'^[AM][0-9AM()]+'),
|
||||
CASE WHEN highway = 'motorway' THEN 'omt-gb-motorway' ELSE 'omt-gb-trunk' END
|
||||
FROM osm_highway_linestring
|
||||
WHERE length(ref) > 0
|
||||
AND ST_Intersects(geometry, (SELECT * FROM ne_10m_admin_0_bg_buffer))
|
||||
AND highway IN ('motorway', 'trunk')
|
||||
;
|
||||
-- Create GBR relations (so we can use it in the same way as other relations)
|
||||
DELETE
|
||||
FROM osm_route_member
|
||||
WHERE network IN ('omt-gb-motorway', 'omt-gb-trunk');
|
||||
-- etldoc: osm_highway_linestring -> osm_route_member
|
||||
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
|
||||
$$
|
||||
SELECT CASE
|
||||
WHEN network = 'US:I' THEN 'us-interstate'::route_network_type
|
||||
WHEN network = 'US:US' THEN 'us-highway'::route_network_type
|
||||
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 = 'omt-gb-motorway' THEN 'gb-motorway'::route_network_type
|
||||
WHEN network = 'omt-gb-trunk' THEN 'gb-trunk'::route_network_type
|
||||
END;
|
||||
$$ LANGUAGE sql IMMUTABLE
|
||||
PARALLEL SAFE;
|
||||
|
||||
-- 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)
|
||||
WHERE network != ''
|
||||
AND network_type IS DISTINCT FROM osm_route_member_network_type(network)
|
||||
;
|
||||
|
||||
CREATE OR REPLACE FUNCTION update_osm_route_member() RETURNS void AS
|
||||
$$
|
||||
BEGIN
|
||||
DELETE
|
||||
FROM osm_route_member AS r
|
||||
USING
|
||||
transportation_name.network_changes AS c
|
||||
WHERE network IN ('omt-gb-motorway', 'omt-gb-trunk')
|
||||
AND r.osm_id = c.osm_id;
|
||||
|
||||
INSERT INTO osm_route_member (osm_id, member, ref, network)
|
||||
SELECT r.*
|
||||
FROM gbr_route_members_view AS r
|
||||
JOIN transportation_name.network_changes AS c ON
|
||||
r.osm_id = c.osm_id;
|
||||
|
||||
UPDATE
|
||||
osm_route_member AS r
|
||||
SET network_type = osm_route_member_network_type(network)
|
||||
FROM transportation_name.network_changes AS c
|
||||
WHERE network != ''
|
||||
AND network_type IS DISTINCT FROM osm_route_member_network_type(network)
|
||||
AND r.member = c.osm_id;
|
||||
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_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");
|
||||
|
||||
CREATE INDEX IF NOT EXISTS osm_route_member_network_type_idx ON osm_route_member ("network_type");
|
||||
|
||||
ALTER TABLE osm_route_member ADD COLUMN IF NOT EXISTS concurrency_index int;
|
||||
|
||||
INSERT INTO osm_route_member (id, concurrency_index)
|
||||
SELECT
|
||||
id,
|
||||
ROW_NUMBER() over (PARTITION BY member ORDER BY network_type, network, LENGTH(ref), ref) AS concurrency_index
|
||||
FROM osm_route_member
|
||||
ON CONFLICT (id) DO UPDATE SET concurrency_index = EXCLUDED.concurrency_index;
|
||||
Reference in New Issue
Block a user