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.
![image](https://user-images.githubusercontent.com/3254090/126420985-c380b54b-a991-4a7c-a4c1-40a5cf5ec6b0.png)

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:
![image](https://user-images.githubusercontent.com/3254090/126421148-71e780ec-991d-4e38-a82a-85015b349e97.png)
This commit is contained in:
Brian Sperlongano 2021-08-04 04:10:16 -04:00 committed by GitHub
parent 9e4be3e3b0
commit 08bb2a06c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 57 additions and 8 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 552 KiB

After

Width:  |  Height:  |  Size: 556 KiB

View File

@ -15,6 +15,7 @@ CREATE OR REPLACE FUNCTION layer_transportation(bbox geometry, zoom_level int)
geometry geometry,
class text,
subclass text,
network text,
ramp int,
oneway int,
brunnel text,
@ -47,6 +48,7 @@ SELECT osm_id,
THEN COALESCE(NULLIF(public_transport, ''), highway)
WHEN aerialway IS NOT NULL THEN aerialway
END AS subclass,
NULLIF(network, '') AS network,
-- All links are considered as ramps as well
CASE
WHEN highway_is_link(highway) OR highway = 'steps'
@ -69,6 +71,7 @@ FROM (
geometry,
highway,
construction,
network,
NULL AS railway,
NULL AS aerialway,
NULL AS shipway,
@ -98,6 +101,7 @@ FROM (
geometry,
highway,
construction,
network,
NULL AS railway,
NULL AS aerialway,
NULL AS shipway,
@ -127,6 +131,7 @@ FROM (
geometry,
highway,
construction,
network,
NULL AS railway,
NULL AS aerialway,
NULL AS shipway,
@ -156,6 +161,7 @@ FROM (
geometry,
highway,
construction,
network,
NULL AS railway,
NULL AS aerialway,
NULL AS shipway,
@ -185,6 +191,7 @@ FROM (
geometry,
highway,
construction,
network,
NULL AS railway,
NULL AS aerialway,
NULL AS shipway,
@ -214,6 +221,7 @@ FROM (
geometry,
highway,
construction,
network,
NULL AS railway,
NULL AS aerialway,
NULL AS shipway,
@ -243,6 +251,7 @@ FROM (
geometry,
highway,
construction,
network,
NULL AS railway,
NULL AS aerialway,
NULL AS shipway,
@ -272,6 +281,7 @@ FROM (
geometry,
highway,
construction,
network,
NULL AS railway,
NULL AS aerialway,
NULL AS shipway,
@ -303,6 +313,7 @@ FROM (
geometry,
highway,
construction,
network,
NULL AS railway,
NULL AS aerialway,
NULL AS shipway,
@ -351,6 +362,7 @@ FROM (
geometry,
NULL AS highway,
NULL AS construction,
NULL AS network,
railway,
NULL AS aerialway,
NULL AS shipway,
@ -383,6 +395,7 @@ FROM (
geometry,
NULL AS highway,
NULL AS construction,
NULL AS network,
railway,
NULL AS aerialway,
NULL AS shipway,
@ -415,6 +428,7 @@ FROM (
geometry,
NULL AS highway,
NULL AS construction,
NULL AS network,
railway,
NULL AS aerialway,
NULL AS shipway,
@ -446,6 +460,7 @@ FROM (
geometry,
NULL AS highway,
NULL AS construction,
NULL AS network,
railway,
NULL AS aerialway,
NULL AS shipway,
@ -477,6 +492,7 @@ FROM (
geometry,
NULL AS highway,
NULL AS construction,
NULL AS network,
railway,
NULL AS aerialway,
NULL AS shipway,
@ -509,6 +525,7 @@ FROM (
geometry,
NULL AS highway,
NULL AS construction,
NULL AS network,
railway,
NULL AS aerialway,
NULL AS shipway,
@ -541,6 +558,7 @@ FROM (
geometry,
NULL AS highway,
NULL AS construction,
NULL AS network,
NULL AS railway,
aerialway,
NULL AS shipway,
@ -571,6 +589,7 @@ FROM (
geometry,
NULL AS highway,
NULL AS construction,
NULL AS network,
NULL AS railway,
aerialway,
NULL AS shipway,
@ -600,6 +619,7 @@ FROM (
geometry,
NULL AS highway,
NULL AS construction,
NULL AS network,
NULL AS railway,
NULL AS aerialway,
shipway,
@ -629,6 +649,7 @@ FROM (
geometry,
NULL AS highway,
NULL AS construction,
NULL AS network,
NULL AS railway,
NULL AS aerialway,
shipway,
@ -659,6 +680,7 @@ FROM (
geometry,
NULL AS highway,
NULL AS construction,
NULL AS network,
NULL AS railway,
NULL AS aerialway,
shipway,
@ -693,6 +715,7 @@ FROM (
geometry,
highway,
NULL AS construction,
NULL AS network,
NULL AS railway,
NULL AS aerialway,
NULL AS shipway,

View File

@ -111,6 +111,12 @@ layer:
- bridleway
- corridor
- platform
network:
description: |
The network type derived mainly from [`network`](http://wiki.openstreetmap.org/wiki/Key:network) tag of the road.
See more info about [`us-*`](http://wiki.openstreetmap.org/wiki/Road_signs_in_the_United_States),
[`ca-transcanada`](https://en.wikipedia.org/wiki/Trans-Canada_Highway),
or [`gb-*`](http://wiki.openstreetmap.org/wiki/United_Kingdom_Tagging_Guidelines#UK_roads).
brunnel:
description: |
Mark whether way is a tunnel or bridge.
@ -174,9 +180,11 @@ layer:
datasource:
geometry_field: geometry
srid: 900913
query: (SELECT geometry, class, subclass, oneway, ramp, brunnel, service, layer, level, indoor, bicycle, foot, horse, mtb_scale, surface FROM layer_transportation(!bbox!, z(!scale_denominator!))) AS t
query: (SELECT geometry, class, subclass, network, oneway, ramp, brunnel, service, layer, level, indoor, bicycle, foot, horse, mtb_scale, surface FROM layer_transportation(!bbox!, z(!scale_denominator!))) AS t
schema:
- ./network_type.sql
- ./class.sql
- ./update_route_member.sql
- ./update_transportation_merge.sql
- ./transportation.sql
datasources:

View File

@ -85,3 +85,13 @@ INSERT INTO osm_route_member (id, concurrency_index)
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;
UPDATE osm_highway_linestring hl
SET network = rm.network_type
FROM osm_route_member rm
WHERE hl.osm_id=rm.member AND rm.concurrency_index=1;
UPDATE osm_highway_linestring_gen_z11 hl
SET network = rm.network_type
FROM osm_route_member rm
WHERE hl.osm_id=rm.member AND rm.concurrency_index=1;

View File

@ -19,6 +19,7 @@ CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z11 AS
SELECT (ST_Dump(geometry)).geom AS geometry,
NULL::bigint AS osm_id,
highway,
network,
construction,
is_bridge,
is_tunnel,
@ -32,6 +33,7 @@ SELECT (ST_Dump(geometry)).geom AS geometry,
FROM (
SELECT ST_LineMerge(ST_Collect(geometry)) AS geometry,
highway,
network,
construction,
is_bridge,
is_tunnel,
@ -44,7 +46,7 @@ FROM (
layer
FROM osm_highway_linestring_gen_z11
WHERE ST_IsValid(geometry)
GROUP BY highway, construction, is_bridge, is_tunnel, is_ford, bicycle, foot, horse, mtb_scale, layer
GROUP BY highway, network, construction, is_bridge, is_tunnel, is_ford, bicycle, foot, horse, mtb_scale, layer
) AS highway_union
) /* DELAY_MATERIALIZED_VIEW_CREATION */;
CREATE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen_z11_geometry_idx
@ -57,6 +59,7 @@ CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z10 AS
SELECT ST_Simplify(geometry, ZRes(12)) AS geometry,
osm_id,
highway,
network,
construction,
is_bridge,
is_tunnel,
@ -81,6 +84,7 @@ CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z9 AS
SELECT ST_Simplify(geometry, ZRes(11)) AS geometry,
osm_id,
highway,
network,
construction,
is_bridge,
is_tunnel,
@ -105,6 +109,7 @@ CREATE MATERIALIZED VIEW osm_transportation_merge_linestring AS
SELECT (ST_Dump(geometry)).geom AS geometry,
NULL::bigint AS osm_id,
highway,
network,
construction,
is_bridge,
is_tunnel,
@ -113,6 +118,7 @@ SELECT (ST_Dump(geometry)).geom AS geometry,
FROM (
SELECT ST_LineMerge(ST_Collect(geometry)) AS geometry,
highway,
network,
construction,
is_bridge,
is_tunnel,
@ -122,7 +128,7 @@ FROM (
WHERE (highway IN ('motorway', 'trunk', 'primary') OR
highway = 'construction' AND construction IN ('motorway', 'trunk', 'primary'))
AND ST_IsValid(geometry)
GROUP BY highway, construction, is_bridge, is_tunnel, is_ford
GROUP BY highway, network, construction, is_bridge, is_tunnel, is_ford
) AS highway_union
) /* DELAY_MATERIALIZED_VIEW_CREATION */;
CREATE INDEX IF NOT EXISTS osm_transportation_merge_linestring_geometry_idx
@ -135,6 +141,7 @@ CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z8 AS
SELECT ST_Simplify(geometry, ZRes(10)) AS geometry,
osm_id,
highway,
network,
construction,
is_bridge,
is_tunnel,
@ -154,6 +161,7 @@ CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z7 AS
SELECT ST_Simplify(geometry, ZRes(9)) AS geometry,
osm_id,
highway,
network,
construction,
is_bridge,
is_tunnel,
@ -174,6 +182,7 @@ CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z6 AS
SELECT ST_Simplify(geometry, ZRes(8)) AS geometry,
osm_id,
highway,
network,
construction,
is_bridge,
is_tunnel,
@ -193,6 +202,7 @@ CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z5 AS
SELECT ST_Simplify(geometry, ZRes(7)) AS geometry,
osm_id,
highway,
network,
construction,
is_bridge,
is_tunnel,
@ -212,6 +222,7 @@ CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z4 AS
SELECT ST_Simplify(geometry, ZRes(6)) AS geometry,
osm_id,
highway,
network,
construction,
is_bridge,
is_tunnel,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 232 KiB

After

Width:  |  Height:  |  Size: 258 KiB

View File

@ -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;

View File

@ -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: