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,
```
This commit is contained in:
parent
9f4d48cf25
commit
6801353e15
3
Makefile
3
Makefile
@ -65,7 +65,8 @@ build/mapping.yaml: build
|
|||||||
docker-compose run $(DC_OPTS) openmaptiles-tools generate-imposm3 openmaptiles.yaml > $@
|
docker-compose run $(DC_OPTS) openmaptiles-tools generate-imposm3 openmaptiles.yaml > $@
|
||||||
|
|
||||||
build/tileset.sql: build
|
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
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
@ -31,9 +31,6 @@ CREATE OR REPLACE FUNCTION poi_class(subclass TEXT, mapping_key TEXT)
|
|||||||
RETURNS TEXT AS $$
|
RETURNS TEXT AS $$
|
||||||
SELECT CASE
|
SELECT CASE
|
||||||
%%FIELD_MAPPING: class %%
|
%%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
|
ELSE subclass
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE SQL IMMUTABLE;
|
$$ LANGUAGE SQL IMMUTABLE;
|
||||||
|
|||||||
@ -36,7 +36,14 @@ layer:
|
|||||||
bus:
|
bus:
|
||||||
subclass: ['bus_stop', 'bus_station']
|
subclass: ['bus_stop', 'bus_station']
|
||||||
railway:
|
railway:
|
||||||
|
- __AND__:
|
||||||
|
subclass: 'station'
|
||||||
|
mapping_key: 'railway'
|
||||||
|
- subclass: ['halt', 'tram_stop', 'subway']
|
||||||
aerialway:
|
aerialway:
|
||||||
|
__AND__:
|
||||||
|
subclass: 'station'
|
||||||
|
mapping_key: 'aerialway'
|
||||||
entrance:
|
entrance:
|
||||||
subclass: ['subway_entrance', 'train_station_entrance']
|
subclass: ['subway_entrance', 'train_station_entrance']
|
||||||
campsite:
|
campsite:
|
||||||
|
|||||||
@ -11,19 +11,6 @@ $$ LANGUAGE SQL IMMUTABLE STRICT;
|
|||||||
CREATE OR REPLACE FUNCTION highway_class(highway TEXT, public_transport TEXT, construction TEXT) RETURNS TEXT AS $$
|
CREATE OR REPLACE FUNCTION highway_class(highway TEXT, public_transport TEXT, construction TEXT) RETURNS TEXT AS $$
|
||||||
SELECT CASE
|
SELECT CASE
|
||||||
%%FIELD_MAPPING: class %%
|
%%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;
|
END;
|
||||||
$$ LANGUAGE SQL IMMUTABLE;
|
$$ LANGUAGE SQL IMMUTABLE;
|
||||||
|
|
||||||
|
|||||||
@ -46,15 +46,47 @@ layer:
|
|||||||
raceway:
|
raceway:
|
||||||
highway: raceway
|
highway: raceway
|
||||||
motorway_construction:
|
motorway_construction:
|
||||||
|
__AND__:
|
||||||
|
highway: construction
|
||||||
|
construction: ['motorway', 'motorway_link']
|
||||||
trunk_construction:
|
trunk_construction:
|
||||||
|
__AND__:
|
||||||
|
highway: construction
|
||||||
|
construction: ['trunk', 'trunk_link']
|
||||||
primary_construction:
|
primary_construction:
|
||||||
|
__AND__:
|
||||||
|
highway: construction
|
||||||
|
construction: ['primary', 'primary_link']
|
||||||
secondary_construction:
|
secondary_construction:
|
||||||
|
__AND__:
|
||||||
|
highway: construction
|
||||||
|
construction: ['secondary', 'secondary_link']
|
||||||
tertiary_construction:
|
tertiary_construction:
|
||||||
|
__AND__:
|
||||||
|
highway: construction
|
||||||
|
construction: ['tertiary', 'tertiary_link']
|
||||||
minor_construction:
|
minor_construction:
|
||||||
|
__AND__:
|
||||||
|
highway: construction
|
||||||
|
construction: ['', 'unclassified', 'residential', 'living_street', 'road']
|
||||||
path_construction:
|
path_construction:
|
||||||
|
__AND__:
|
||||||
|
- highway: construction
|
||||||
|
- __OR__:
|
||||||
|
construction: ['pedestrian', 'path', 'footway', 'cycleway', 'steps', 'bridleway', 'corridor']
|
||||||
|
public_transport: platform
|
||||||
service_construction:
|
service_construction:
|
||||||
|
__AND__:
|
||||||
|
highway: construction
|
||||||
|
construction: service
|
||||||
track_construction:
|
track_construction:
|
||||||
|
__AND__:
|
||||||
|
highway: construction
|
||||||
|
construction: track
|
||||||
raceway_construction:
|
raceway_construction:
|
||||||
|
__AND__:
|
||||||
|
highway: construction
|
||||||
|
construction: raceway
|
||||||
subclass:
|
subclass:
|
||||||
description: |
|
description: |
|
||||||
Distinguish more specific classes of railway and path:
|
Distinguish more specific classes of railway and path:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user