From 6801353e1555b91fda79f3dd3a24e647b4e3e896 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Fri, 31 Jan 2020 00:22:21 -0500 Subject: [PATCH] Declared field mapping 2 (#734) Make a few more mappings declarative, and removes values declared in both SQL and the yaml file. Here's the diff comparing `build/tileset.sql` in master vs the new PR. The changes are mostly stylistic, except when a nested `if` statement is expanded into individual `if ... and ...` conditions (logically identical) ```diff 55c55 diff --git a/build/tileset.sql b/build/tileset.sql index 4e59357..7c6c444 100644 --- a/build/tileset.sql +++ b/build/tileset.sql @@ -52,7 +52,7 @@ CREATE INDEX IF NOT EXISTS osm_ocean_polygon_gen4_idx ON osm_ocean_polygon_gen4 CREATE OR REPLACE FUNCTION water_class(waterway TEXT) RETURNS TEXT AS $$ SELECT CASE WHEN "waterway" IN ('', 'lake') THEN 'lake' - WHEN "waterway"='dock' THEN 'dock' + WHEN "waterway" = 'dock' THEN 'dock' ELSE 'river' END; $$ LANGUAGE SQL IMMUTABLE; @@ -1813,24 +1813,41 @@ CREATE OR REPLACE FUNCTION highway_class(highway TEXT, public_transport TEXT, co WHEN "highway" IN ('tertiary', 'tertiary_link') THEN 'tertiary' WHEN "highway" IN ('unclassified', 'residential', 'living_street', 'road') THEN 'minor' WHEN "highway" IN ('pedestrian', 'path', 'footway', 'cycleway', 'steps', 'bridleway', 'corridor') - OR "public_transport"='platform' + OR "public_transport" = 'platform' THEN 'path' - WHEN "highway"='service' THEN 'service' - WHEN "highway"='track' THEN 'track' - WHEN "highway"='raceway' THEN 'raceway' - WHEN highway = 'construction' THEN CASE - WHEN construction IN ('motorway', 'motorway_link') THEN 'motorway_construction' - WHEN construction IN ('trunk', 'trunk_link') THEN 'trunk_construction' - WHEN construction IN ('primary', 'primary_link') THEN 'primary_construction' - WHEN construction IN ('secondary', 'secondary_link') THEN 'secondary_construction' - WHEN construction IN ('tertiary', 'tertiary_link') THEN 'tertiary_construction' - WHEN construction IN ('', 'unclassified', 'residential', 'living_street', 'road') THEN 'minor_construction' - WHEN construction IN ('pedestrian', 'path', 'footway', 'cycleway', 'steps', 'bridleway', 'corridor') - OR public_transport = 'platform' THEN 'path_construction' - WHEN construction = 'service' THEN 'service_construction' - WHEN construction = 'track' THEN 'track_construction' - WHEN construction = 'raceway' THEN 'raceway_construction' - END + WHEN "highway" = 'service' THEN 'service' + WHEN "highway" = 'track' THEN 'track' + WHEN "highway" = 'raceway' THEN 'raceway' + WHEN "highway" = 'construction' + AND "construction" IN ('motorway', 'motorway_link') + THEN 'motorway_construction' + WHEN "highway" = 'construction' + AND "construction" IN ('trunk', 'trunk_link') + THEN 'trunk_construction' + WHEN "highway" = 'construction' + AND "construction" IN ('primary', 'primary_link') + THEN 'primary_construction' + WHEN "highway" = 'construction' + AND "construction" IN ('secondary', 'secondary_link') + THEN 'secondary_construction' + WHEN "highway" = 'construction' + AND "construction" IN ('tertiary', 'tertiary_link') + THEN 'tertiary_construction' + WHEN "highway" = 'construction' + AND "construction" IN ('', 'unclassified', 'residential', 'living_street', 'road') + THEN 'minor_construction' + WHEN "highway" = 'construction' + AND ("construction" IN ('pedestrian', 'path', 'footway', 'cycleway', 'steps', 'bridleway', 'corridor') OR "public_transport" = 'platform') + THEN 'path_construction' + WHEN "highway" = 'construction' + AND "construction" = 'service' + THEN 'service_construction' + WHEN "highway" = 'construction' + AND "construction" = 'track' + THEN 'track_construction' + WHEN "highway" = 'construction' + AND "construction" = 'raceway' + THEN 'raceway_construction' END; $$ LANGUAGE SQL IMMUTABLE; @@ -4073,6 +4090,12 @@ RETURNS TEXT AS $$ WHEN "subclass" IN ('fast_food', 'food_court') THEN 'fast_food' WHEN "subclass" IN ('park', 'bbq') THEN 'park' WHEN "subclass" IN ('bus_stop', 'bus_station') THEN 'bus' + WHEN ("subclass" = 'station' AND "mapping_key" = 'railway') + OR "subclass" IN ('halt', 'tram_stop', 'subway') + THEN 'railway' + WHEN "subclass" = 'station' + AND "mapping_key" = 'aerialway' + THEN 'aerialway' WHEN "subclass" IN ('subway_entrance', 'train_station_entrance') THEN 'entrance' WHEN "subclass" IN ('camp_site', 'caravan_site') THEN 'campsite' WHEN "subclass" IN ('laundry', 'dry_cleaning') THEN 'laundry' @@ -4082,7 +4105,7 @@ RETURNS TEXT AS $$ WHEN "subclass" IN ('hotel', 'motel', 'bed_and_breakfast', 'guest_house', 'hostel', 'chalet', 'alpine_hut', 'dormitory') THEN 'lodging' WHEN "subclass" IN ('chocolate', 'confectionery') THEN 'ice_cream' WHEN "subclass" IN ('post_box', 'post_office') THEN 'post' - WHEN "subclass"='cafe' THEN 'cafe' + WHEN "subclass" = 'cafe' THEN 'cafe' WHEN "subclass" IN ('school', 'kindergarten') THEN 'school' WHEN "subclass" IN ('alcohol', 'beverages', 'wine') THEN 'alcohol_shop' WHEN "subclass" IN ('bar', 'nightclub') THEN 'bar' @@ -4098,9 +4121,6 @@ RETURNS TEXT AS $$ WHEN "subclass" IN ('bag', 'clothes') THEN 'clothing_store' WHEN "subclass" IN ('swimming_area', 'swimming') THEN 'swimming' WHEN "subclass" IN ('castle', 'ruins') THEN 'castle' - WHEN (subclass = 'station' AND mapping_key = 'railway') - OR (subclass IN ('halt', 'tram_stop', 'subway')) THEN 'railway' - WHEN (subclass = 'station' AND mapping_key = 'aerialway') THEN 'aerialway' ELSE subclass END; $$ LANGUAGE SQL IMMUTABLE; @@ -4301,22 +4321,22 @@ $$ COALESCE(NULLIF(name_de, ''), name, name_en) AS name_de, tags, CASE - WHEN "aerodrome"='international' - OR "aerodrome_type"='international' + WHEN "aerodrome" = 'international' + OR "aerodrome_type" = 'international' THEN 'international' - WHEN "aerodrome"='public' - OR "aerodrome_type"='civil' + WHEN "aerodrome" = 'public' + OR "aerodrome_type" = 'civil' OR "aerodrome_type" LIKE '%public%' THEN 'public' - WHEN "aerodrome"='regional' - OR "aerodrome_type"='regional' + WHEN "aerodrome" = 'regional' + OR "aerodrome_type" = 'regional' THEN 'regional' - WHEN "aerodrome"='military' + WHEN "aerodrome" = 'military' OR "aerodrome_type" LIKE '%military%' - OR "military"='airfield' + OR "military" = 'airfield' THEN 'military' - WHEN "aerodrome"='private' - OR "aerodrome_type"='private' + WHEN "aerodrome" = 'private' + OR "aerodrome_type" = 'private' THEN 'private' ELSE 'other' END AS class, ``` --- Makefile | 3 ++- layers/poi/class.sql | 3 --- layers/poi/poi.yaml | 7 +++++ layers/transportation/class.sql | 13 --------- layers/transportation/transportation.yaml | 32 +++++++++++++++++++++++ 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 86587ef..f7ed98a 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,8 @@ build/mapping.yaml: build docker-compose run $(DC_OPTS) openmaptiles-tools generate-imposm3 openmaptiles.yaml > $@ build/tileset.sql: build - docker-compose run $(DC_OPTS) openmaptiles-tools generate-sql openmaptiles.yaml > $@ + # FIXME: switch to openmaptiles-tools after v3.2+ is published + docker-compose run $(DC_OPTS) openmaptiles-tools-latest generate-sql openmaptiles.yaml > $@ .PHONY: clean clean: diff --git a/layers/poi/class.sql b/layers/poi/class.sql index c81573a..74c3190 100644 --- a/layers/poi/class.sql +++ b/layers/poi/class.sql @@ -31,9 +31,6 @@ CREATE OR REPLACE FUNCTION poi_class(subclass TEXT, mapping_key TEXT) RETURNS TEXT AS $$ SELECT CASE %%FIELD_MAPPING: class %% - WHEN (subclass = 'station' AND mapping_key = 'railway') - OR (subclass IN ('halt', 'tram_stop', 'subway')) THEN 'railway' - WHEN (subclass = 'station' AND mapping_key = 'aerialway') THEN 'aerialway' ELSE subclass END; $$ LANGUAGE SQL IMMUTABLE; diff --git a/layers/poi/poi.yaml b/layers/poi/poi.yaml index 8ed707d..d678bd6 100644 --- a/layers/poi/poi.yaml +++ b/layers/poi/poi.yaml @@ -36,7 +36,14 @@ layer: bus: subclass: ['bus_stop', 'bus_station'] railway: + - __AND__: + subclass: 'station' + mapping_key: 'railway' + - subclass: ['halt', 'tram_stop', 'subway'] aerialway: + __AND__: + subclass: 'station' + mapping_key: 'aerialway' entrance: subclass: ['subway_entrance', 'train_station_entrance'] campsite: diff --git a/layers/transportation/class.sql b/layers/transportation/class.sql index 8ed42ab..0bf33ae 100644 --- a/layers/transportation/class.sql +++ b/layers/transportation/class.sql @@ -11,19 +11,6 @@ $$ LANGUAGE SQL IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION highway_class(highway TEXT, public_transport TEXT, construction TEXT) RETURNS TEXT AS $$ SELECT CASE %%FIELD_MAPPING: class %% - WHEN highway = 'construction' THEN CASE - WHEN construction IN ('motorway', 'motorway_link') THEN 'motorway_construction' - WHEN construction IN ('trunk', 'trunk_link') THEN 'trunk_construction' - WHEN construction IN ('primary', 'primary_link') THEN 'primary_construction' - WHEN construction IN ('secondary', 'secondary_link') THEN 'secondary_construction' - WHEN construction IN ('tertiary', 'tertiary_link') THEN 'tertiary_construction' - WHEN construction IN ('', 'unclassified', 'residential', 'living_street', 'road') THEN 'minor_construction' - WHEN construction IN ('pedestrian', 'path', 'footway', 'cycleway', 'steps', 'bridleway', 'corridor') - OR public_transport = 'platform' THEN 'path_construction' - WHEN construction = 'service' THEN 'service_construction' - WHEN construction = 'track' THEN 'track_construction' - WHEN construction = 'raceway' THEN 'raceway_construction' - END END; $$ LANGUAGE SQL IMMUTABLE; diff --git a/layers/transportation/transportation.yaml b/layers/transportation/transportation.yaml index f4da3c3..700d8b2 100644 --- a/layers/transportation/transportation.yaml +++ b/layers/transportation/transportation.yaml @@ -46,15 +46,47 @@ layer: raceway: highway: raceway motorway_construction: + __AND__: + highway: construction + construction: ['motorway', 'motorway_link'] trunk_construction: + __AND__: + highway: construction + construction: ['trunk', 'trunk_link'] primary_construction: + __AND__: + highway: construction + construction: ['primary', 'primary_link'] secondary_construction: + __AND__: + highway: construction + construction: ['secondary', 'secondary_link'] tertiary_construction: + __AND__: + highway: construction + construction: ['tertiary', 'tertiary_link'] minor_construction: + __AND__: + highway: construction + construction: ['', 'unclassified', 'residential', 'living_street', 'road'] path_construction: + __AND__: + - highway: construction + - __OR__: + construction: ['pedestrian', 'path', 'footway', 'cycleway', 'steps', 'bridleway', 'corridor'] + public_transport: platform service_construction: + __AND__: + highway: construction + construction: service track_construction: + __AND__: + highway: construction + construction: track raceway_construction: + __AND__: + highway: construction + construction: raceway subclass: description: | Distinguish more specific classes of railway and path: