From 7f23feab88ffb11e40a27986f93b955baede9328 Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Fri, 26 Nov 2021 01:55:20 -0500 Subject: [PATCH] Add expressway tagging to the transportation layer (#1313) Fixes #1148 This PR adds expressway tagging to the `transportation` layer, by setting `expressway=1` for non-motorway roads tagged `expressway=yes`, and omitting the tag otherwise. Additionally, I've added a few unit tests to verify that the expressway tagging is being imported and updated into the intermediate tables. Here is an example of expressway tagging on US-1 in Rhode Island, USA: ![image](https://user-images.githubusercontent.com/3254090/143501278-db3671b2-2efa-4998-bffd-9ddfec63579b.png) --- layers/transportation/mapping.yaml | 5 ++ layers/transportation/transportation.sql | 61 +++++++++++++------ layers/transportation/transportation.yaml | 6 +- .../update_transportation_merge.sql | 9 ++- tests/import/500_import-highway.osm | 1 + tests/test-post-import.sql | 7 +++ tests/test-post-update.sql | 8 +++ tests/update/500_update-highway.osc | 7 +++ 8 files changed, 82 insertions(+), 22 deletions(-) diff --git a/layers/transportation/mapping.yaml b/layers/transportation/mapping.yaml index ee4e92d7..00d804b0 100644 --- a/layers/transportation/mapping.yaml +++ b/layers/transportation/mapping.yaml @@ -159,6 +159,10 @@ surface_field: &surface key: surface name: surface type: string +expressway_field: &expressway + key: expressway + name: expressway + type: bool tables: # etldoc: imposm3 -> osm_highway_linestring @@ -206,6 +210,7 @@ tables: - *mtb_scale - *sac_scale - *surface + - *expressway mapping: highway: - motorway diff --git a/layers/transportation/transportation.sql b/layers/transportation/transportation.sql index 59b8243d..fd7a22f8 100644 --- a/layers/transportation/transportation.sql +++ b/layers/transportation/transportation.sql @@ -11,25 +11,26 @@ $$ LANGUAGE SQL IMMUTABLE CREATE OR REPLACE FUNCTION layer_transportation(bbox geometry, zoom_level int) RETURNS TABLE ( - osm_id bigint, - geometry geometry, - class text, - subclass text, - network text, - ramp int, - oneway int, - brunnel text, - service text, - access text, - toll int, - layer int, - level int, - indoor int, - bicycle text, - foot text, - horse text, - mtb_scale text, - surface text + osm_id bigint, + geometry geometry, + class text, + subclass text, + network text, + ramp int, + oneway int, + brunnel text, + service text, + access text, + toll int, + expressway int, + layer int, + level int, + indoor int, + bicycle text, + foot text, + horse text, + mtb_scale text, + surface text ) AS $$ @@ -61,6 +62,7 @@ SELECT osm_id, NULLIF(service, '') AS service, access, CASE WHEN toll = TRUE THEN 1 END AS toll, + CASE WHEN highway NOT IN ('', 'motorway') AND expressway = TRUE THEN 1 END AS expressway, NULLIF(layer, 0) AS layer, "level", CASE WHEN indoor = TRUE THEN 1 END AS indoor, @@ -86,6 +88,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + NULL::boolean AS expressway, NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL AS man_made, @@ -118,6 +121,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + NULL::boolean AS expressway, NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL AS man_made, @@ -150,6 +154,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + NULL::boolean AS expressway, NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL AS man_made, @@ -182,6 +187,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + expressway, NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL AS man_made, @@ -214,6 +220,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + expressway, NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL AS man_made, @@ -246,6 +253,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + expressway, NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL AS man_made, @@ -278,6 +286,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + expressway, NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL AS man_made, @@ -310,6 +319,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + expressway, NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL AS man_made, @@ -347,6 +357,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + expressway, is_ramp, is_oneway, man_made, @@ -399,6 +410,7 @@ FROM ( NULL::boolean AS is_bridge, NULL::boolean AS is_tunnel, NULL::boolean AS is_ford, + NULL::boolean AS expressway, NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL AS man_made, @@ -434,6 +446,7 @@ FROM ( NULL::boolean AS is_bridge, NULL::boolean AS is_tunnel, NULL::boolean AS is_ford, + NULL::boolean AS expressway, NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL AS man_made, @@ -469,6 +482,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + NULL::boolean AS expressway, is_ramp, is_oneway, NULL AS man_made, @@ -503,6 +517,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + NULL::boolean AS expressway, is_ramp, is_oneway, NULL AS man_made, @@ -537,6 +552,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + NULL::boolean AS expressway, is_ramp, is_oneway, NULL AS man_made, @@ -572,6 +588,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + NULL::boolean AS expressway, is_ramp, is_oneway, NULL AS man_made, @@ -607,6 +624,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + NULL::boolean AS expressway, is_ramp, is_oneway, NULL AS man_made, @@ -640,6 +658,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + NULL::boolean AS expressway, is_ramp, is_oneway, NULL AS man_made, @@ -672,6 +691,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + NULL::boolean AS expressway, is_ramp, is_oneway, NULL AS man_made, @@ -704,6 +724,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + NULL::boolean AS expressway, is_ramp, is_oneway, NULL AS man_made, @@ -737,6 +758,7 @@ FROM ( is_bridge, is_tunnel, is_ford, + NULL::boolean AS expressway, is_ramp, is_oneway, NULL AS man_made, @@ -777,6 +799,7 @@ FROM ( END AS is_bridge, FALSE AS is_tunnel, FALSE AS is_ford, + NULL::boolean AS expressway, FALSE AS is_ramp, FALSE::int AS is_oneway, man_made, diff --git a/layers/transportation/transportation.yaml b/layers/transportation/transportation.yaml index 6ca30f58..f7897aa5 100644 --- a/layers/transportation/transportation.yaml +++ b/layers/transportation/transportation.yaml @@ -162,6 +162,10 @@ layer: description: | Whether this is a toll road, based on the [`toll`](http://wiki.openstreetmap.org/wiki/Key:toll) tag. values: [0, 1] + expressway: + description: | + Whether this is an expressway, based on the [`expressway`](http://wiki.openstreetmap.org/wiki/Key:expressway) tag. + values: [1] layer: description: | Original value of the [`layer`](http://wiki.openstreetmap.org/wiki/Key:layer) tag. @@ -196,7 +200,7 @@ layer: datasource: geometry_field: geometry srid: 900913 - query: (SELECT geometry, class, subclass, network, oneway, ramp, brunnel, service, access, toll, 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, access, toll, expressway, layer, level, indoor, bicycle, foot, horse, mtb_scale, surface FROM layer_transportation(!bbox!, z(!scale_denominator!))) AS t schema: - ./network_type.sql - ./class.sql diff --git a/layers/transportation/update_transportation_merge.sql b/layers/transportation/update_transportation_merge.sql index 7418774c..6c0de7e2 100644 --- a/layers/transportation/update_transportation_merge.sql +++ b/layers/transportation/update_transportation_merge.sql @@ -82,6 +82,7 @@ SELECT (ST_Dump(ST_LineMerge(ST_Collect(geometry)))).geom AS geometry, is_bridge, is_tunnel, is_ford, + expressway, min(z_order) as z_order, bicycle, foot, @@ -95,7 +96,7 @@ SELECT (ST_Dump(ST_LineMerge(ST_Collect(geometry)))).geom AS geometry, layer FROM osm_highway_linestring_gen_z11 -- mapping.yaml pre-filter: motorway/trunk/primary/secondary/tertiary, with _link variants, construction, ST_IsValid() -GROUP BY highway, network, construction, is_bridge, is_tunnel, is_ford, bicycle, foot, horse, mtb_scale, sac_scale, access, toll, layer +GROUP BY highway, network, construction, is_bridge, is_tunnel, is_ford, expressway, bicycle, foot, horse, mtb_scale, sac_scale, access, toll, layer ) /* DELAY_MATERIALIZED_VIEW_CREATION */; CREATE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen_z11_geometry_idx ON osm_transportation_merge_linestring_gen_z11 USING gist (geometry); @@ -111,6 +112,7 @@ SELECT ST_Simplify(geometry, ZRes(12)) AS geometry, is_bridge, is_tunnel, is_ford, + expressway, z_order, bicycle, foot, @@ -138,6 +140,7 @@ SELECT ST_Simplify(geometry, ZRes(11)) AS geometry, is_bridge, is_tunnel, is_ford, + expressway, z_order, bicycle, foot, @@ -164,13 +167,14 @@ SELECT ST_Simplify(ST_LineMerge(ST_Collect(geometry)), ZRes(10)) AS geometry, is_bridge, is_tunnel, is_ford, + expressway, min(z_order) as z_order FROM osm_transportation_merge_linestring_gen_z9 WHERE (highway IN ('motorway', 'trunk', 'primary') OR construction IN ('motorway', 'trunk', 'primary')) AND ST_IsValid(geometry) AND access IS NULL -GROUP BY highway, network, construction, is_bridge, is_tunnel, is_ford +GROUP BY highway, network, construction, is_bridge, is_tunnel, is_ford, expressway ) /* DELAY_MATERIALIZED_VIEW_CREATION */; CREATE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen_z8_geometry_idx ON osm_transportation_merge_linestring_gen_z8 USING gist (geometry); @@ -186,6 +190,7 @@ SELECT ST_Simplify(geometry, ZRes(9)) AS geometry, is_bridge, is_tunnel, is_ford, + expressway, z_order FROM osm_transportation_merge_linestring_gen_z8 -- Current view: motorway/trunk/primary diff --git a/tests/import/500_import-highway.osm b/tests/import/500_import-highway.osm index 374558f1..7fcbec92 100644 --- a/tests/import/500_import-highway.osm +++ b/tests/import/500_import-highway.osm @@ -37,6 +37,7 @@ + diff --git a/tests/test-post-import.sql b/tests/test-post-import.sql index 63182c6a..8fa194b0 100644 --- a/tests/test-post-import.sql +++ b/tests/test-post-import.sql @@ -133,6 +133,13 @@ BEGIN INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_transportation_linestring z9 import tags expected 1, got ' || cnt); END IF; + SELECT COUNT(*) INTO cnt FROM osm_transportation_merge_linestring_gen_z9 + WHERE highway = 'trunk' + AND expressway = TRUE; + IF cnt < 1 THEN + INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_transportation_linestring z9 import expressway expected >=1, got ' || cnt); + END IF; + -- Same-named road split into 3 parts, because the middle segment is tagged toll=yes SELECT COUNT(*) INTO cnt FROM osm_transportation_name_linestring WHERE tags->'name' = 'OpenMapTiles Secondary 3'; IF cnt <> 2 THEN diff --git a/tests/test-post-update.sql b/tests/test-post-update.sql index 82b4958e..a6f43674 100644 --- a/tests/test-post-update.sql +++ b/tests/test-post-update.sql @@ -55,6 +55,14 @@ BEGIN INSERT INTO omt_test_failures VALUES(500, 'update', 'osm_transportation_linestring unsplit road count expected 1, got ' || cnt); END IF; + -- Verify expressway tag updated + SELECT COUNT(*) INTO cnt FROM osm_transportation_merge_linestring_gen_z9 + WHERE highway = 'primary' + AND expressway = TRUE; + IF cnt < 1 THEN + INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_transportation_linestring z9 update expressway expected >=1, got ' || cnt); + END IF; + -- Verify tags changed SELECT COUNT(*) INTO cnt FROM osm_transportation_merge_linestring_gen_z9 WHERE is_tunnel = TRUE diff --git a/tests/update/500_update-highway.osc b/tests/update/500_update-highway.osc index 89687e69..f5645173 100644 --- a/tests/update/500_update-highway.osc +++ b/tests/update/500_update-highway.osc @@ -5,6 +5,13 @@ Change tags --> + + + + + + +