From 7ca751ec7a3e417e233b076e0af94a8faf55882b Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Thu, 19 Aug 2021 01:12:10 -0400 Subject: [PATCH] Add toll tagging (#1177) Fixes #366 This PR sets `toll=1` in the `transportation` layer when a road is tagged as a toll road in OSM (with the tag `toll=yes`). If a road is tagged with any other value of `tag=*`, the value is suppressed in the tile, since non-toll roads can be presumed as the default and therefore this PR should have only negligible impact in the tiles. Support for toll road tagging is of interest in the American mapping community, because toll roads have historically been styled differently on American-style maps, for example: ![image](https://user-images.githubusercontent.com/3254090/129505967-5916eace-596a-4c89-ac5d-0aab3e641ed7.png) Screen shot of a toll road being generated in the `transportation` layer tiles: ![image](https://user-images.githubusercontent.com/3254090/129505683-eb315643-95ff-455b-a606-f379f776f92d.png) --- layers/transportation/mapping.yaml | 5 ++++ layers/transportation/transportation.sql | 23 +++++++++++++++++++ layers/transportation/transportation.yaml | 6 ++++- .../update_transportation_merge.sql | 12 ++++++---- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/layers/transportation/mapping.yaml b/layers/transportation/mapping.yaml index 5981947..90ec1d3 100644 --- a/layers/transportation/mapping.yaml +++ b/layers/transportation/mapping.yaml @@ -96,6 +96,10 @@ access_field: &access key: access name: access type: string +toll_field: &toll + key: toll + name: toll + type: bool usage_field: &usage key: usage name: usage @@ -188,6 +192,7 @@ tables: - *area - *service - *access + - *toll - *usage - *public_transport - *man_made diff --git a/layers/transportation/transportation.sql b/layers/transportation/transportation.sql index 77107f5..a4cf730 100644 --- a/layers/transportation/transportation.sql +++ b/layers/transportation/transportation.sql @@ -21,6 +21,7 @@ CREATE OR REPLACE FUNCTION layer_transportation(bbox geometry, zoom_level int) brunnel text, service text, access text, + toll int, layer int, level int, indoor int, @@ -59,6 +60,7 @@ SELECT osm_id, brunnel(is_bridge, is_tunnel, is_ford) AS brunnel, NULLIF(service, '') AS service, access, + CASE WHEN toll = TRUE THEN 1 END AS toll, NULLIF(layer, 0) AS layer, "level", CASE WHEN indoor = TRUE THEN 1 END AS indoor, @@ -80,6 +82,7 @@ FROM ( NULL AS public_transport, NULL AS service, NULL AS access, + NULL::boolean AS toll, is_bridge, is_tunnel, is_ford, @@ -111,6 +114,7 @@ FROM ( NULL AS public_transport, NULL AS service, NULL AS access, + NULL::boolean AS toll, is_bridge, is_tunnel, is_ford, @@ -142,6 +146,7 @@ FROM ( NULL AS public_transport, NULL AS service, NULL AS access, + NULL::boolean AS toll, is_bridge, is_tunnel, is_ford, @@ -173,6 +178,7 @@ FROM ( NULL AS public_transport, NULL AS service, NULL AS access, + NULL::boolean AS toll, is_bridge, is_tunnel, is_ford, @@ -204,6 +210,7 @@ FROM ( NULL AS public_transport, NULL AS service, NULL AS access, + NULL::boolean AS toll, is_bridge, is_tunnel, is_ford, @@ -235,6 +242,7 @@ FROM ( NULL AS public_transport, NULL AS service, access, + toll, is_bridge, is_tunnel, is_ford, @@ -266,6 +274,7 @@ FROM ( NULL AS public_transport, NULL AS service, access, + toll, is_bridge, is_tunnel, is_ford, @@ -297,6 +306,7 @@ FROM ( NULL AS public_transport, NULL AS service, access, + toll, is_bridge, is_tunnel, is_ford, @@ -330,6 +340,7 @@ FROM ( public_transport, service_value(service) AS service, CASE WHEN access IN ('private', 'no') THEN 'no' END AS access, + CASE WHEN toll='yes' THEN true ELSE NULL::boolean END AS toll, is_bridge, is_tunnel, is_ford, @@ -380,6 +391,7 @@ FROM ( NULL AS public_transport, service_value(service) AS service, NULL::text AS access, + NULL::boolean AS toll, NULL::boolean AS is_bridge, NULL::boolean AS is_tunnel, NULL::boolean AS is_ford, @@ -414,6 +426,7 @@ FROM ( NULL AS public_transport, service_value(service) AS service, NULL::text AS access, + NULL::boolean AS toll, NULL::boolean AS is_bridge, NULL::boolean AS is_tunnel, NULL::boolean AS is_ford, @@ -448,6 +461,7 @@ FROM ( NULL AS public_transport, service_value(service) AS service, NULL::text AS access, + NULL::boolean AS toll, is_bridge, is_tunnel, is_ford, @@ -481,6 +495,7 @@ FROM ( NULL AS public_transport, service_value(service) AS service, NULL::text AS access, + NULL::boolean AS toll, is_bridge, is_tunnel, is_ford, @@ -514,6 +529,7 @@ FROM ( NULL AS public_transport, service_value(service) AS service, NULL::text AS access, + NULL::boolean AS toll, is_bridge, is_tunnel, is_ford, @@ -548,6 +564,7 @@ FROM ( NULL AS public_transport, service_value(service) AS service, NULL::text AS access, + NULL::boolean AS toll, is_bridge, is_tunnel, is_ford, @@ -582,6 +599,7 @@ FROM ( NULL AS public_transport, service_value(service) AS service, NULL::text AS access, + NULL::boolean AS toll, is_bridge, is_tunnel, is_ford, @@ -614,6 +632,7 @@ FROM ( NULL AS public_transport, service_value(service) AS service, NULL::text AS access, + NULL::boolean AS toll, is_bridge, is_tunnel, is_ford, @@ -645,6 +664,7 @@ FROM ( NULL AS public_transport, service_value(service) AS service, NULL::text AS access, + NULL::boolean AS toll, is_bridge, is_tunnel, is_ford, @@ -676,6 +696,7 @@ FROM ( NULL AS public_transport, service_value(service) AS service, NULL::text AS access, + NULL::boolean AS toll, is_bridge, is_tunnel, is_ford, @@ -708,6 +729,7 @@ FROM ( NULL AS public_transport, service_value(service) AS service, NULL::text AS access, + NULL::boolean AS toll, is_bridge, is_tunnel, is_ford, @@ -744,6 +766,7 @@ FROM ( public_transport, NULL AS service, NULL::text AS access, + NULL::boolean AS toll, CASE WHEN man_made IN ('bridge') THEN TRUE ELSE FALSE diff --git a/layers/transportation/transportation.yaml b/layers/transportation/transportation.yaml index 510a359..fe92426 100644 --- a/layers/transportation/transportation.yaml +++ b/layers/transportation/transportation.yaml @@ -153,6 +153,10 @@ layer: which resolve to `no`. values: - no + toll: + description: | + Whether this is a toll road, based on the [`toll`](http://wiki.openstreetmap.org/wiki/Key:toll) tag. + values: [0, 1] layer: description: | Original value of the [`layer`](http://wiki.openstreetmap.org/wiki/Key:layer) tag. @@ -187,7 +191,7 @@ layer: datasource: geometry_field: geometry srid: 900913 - query: (SELECT geometry, class, subclass, network, oneway, ramp, brunnel, service, access, 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, 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 34ebfde..be6b6af 100644 --- a/layers/transportation/update_transportation_merge.sql +++ b/layers/transportation/update_transportation_merge.sql @@ -30,13 +30,15 @@ SELECT (ST_Dump(ST_LineMerge(ST_Collect(geometry)))).geom AS geometry, horse, mtb_scale, CASE - WHEN access IN ('private', 'no') - THEN 'no' - ELSE NULL::text END AS access, + WHEN access IN ('private', 'no') THEN 'no' + ELSE NULL::text END AS access, + CASE + WHEN toll = 'yes' THEN true + ELSE false END AS toll, 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, access, layer +GROUP BY highway, network, construction, is_bridge, is_tunnel, is_ford, bicycle, foot, horse, mtb_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); @@ -58,6 +60,7 @@ SELECT ST_Simplify(geometry, ZRes(12)) AS geometry, horse, mtb_scale, access, + toll, layer FROM osm_transportation_merge_linestring_gen_z11 WHERE highway NOT IN ('tertiary', 'tertiary_link') @@ -83,6 +86,7 @@ SELECT ST_Simplify(geometry, ZRes(11)) AS geometry, horse, mtb_scale, access, + toll, layer FROM osm_transportation_merge_linestring_gen_z10 -- Current view: motorway/primary/secondary, with _link variants and construction