From c05d8b4462f088dd5212bb562b46447a1727244b Mon Sep 17 00:00:00 2001 From: Matt Amos Date: Wed, 9 Dec 2015 17:03:09 +0000 Subject: [PATCH] Added winter sports POIs and lines. --- data/apply-planet_osm_line.sql | 4 ++-- data/functions.sql | 28 +++++++++++++++++++++++++++- data/triggers.sql | 2 +- queries/boundaries.jinja2 | 2 ++ queries/pois.jinja2 | 4 ++-- queries/roads.jinja2 | 6 ++++++ 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/data/apply-planet_osm_line.sql b/data/apply-planet_osm_line.sql index 1aa07ff0e..4e58bd509 100644 --- a/data/apply-planet_osm_line.sql +++ b/data/apply-planet_osm_line.sql @@ -9,8 +9,8 @@ ALTER TABLE planet_osm_line ADD COLUMN mz_road_level SMALLINT; ALTER TABLE planet_osm_line ADD COLUMN mz_transit_level SMALLINT; UPDATE planet_osm_line - SET mz_road_level = mz_calculate_road_level(highway, railway, aeroway, route, service, aerialway, way) - WHERE mz_calculate_road_level(highway, railway, aeroway, route, service, aerialway, tags->'piste:type', way) IS NOT NULL; + SET mz_road_level = mz_calculate_road_level(highway, railway, aeroway, route, service, aerialway, leisure, sport, way) + WHERE mz_calculate_road_level(highway, railway, aeroway, route, service, aerialway, leisure, sport, way) IS NOT NULL; UPDATE planet_osm_line SET mz_transit_level = mz_calculate_transit_level(route) diff --git a/data/functions.sql b/data/functions.sql index d5f35609b..829e4bef1 100644 --- a/data/functions.sql +++ b/data/functions.sql @@ -110,6 +110,7 @@ CREATE OR REPLACE FUNCTION mz_calculate_poi_level( office_val text, power_val text, railway_val text, + rental_val text, shop_val text, tourism_val text, waterway_val text, @@ -167,6 +168,11 @@ BEGIN WHEN amenity_val = 'ferry_terminal' THEN LEAST(zoom + 3.20, 15) WHEN amenity_val = 'school' THEN LEAST(zoom + 2.30, 15) WHEN natural_val = 'beach' THEN LEAST(zoom + 3.20, 14) + WHEN rental_val = 'ski' THEN LEAST(zoom + 1.27, 17) + WHEN shop_val = 'ski' THEN LEAST(zoom + 1.27, 17) + WHEN amenity_val = 'ski_rental' THEN LEAST(zoom + 1.27, 17) + WHEN amenity_val = 'ski_school' THEN LEAST(zoom + 2.30, 15) + WHEN man_made_val = 'snow_cannon' THEN LEAST(zoom + 4.90, 18) WHEN (barrier_val IN ('gate') OR craft_val IN ('sawmill') OR highway_val IN ('gate', 'mini_roundabout') @@ -303,7 +309,24 @@ BEGIN END; $$ LANGUAGE plpgsql IMMUTABLE; -CREATE OR REPLACE FUNCTION mz_calculate_road_level(highway_val text, railway_val text, aeroway_val text, route_val text, service_val text, aerialway_val text, way geometry) +CREATE OR REPLACE FUNCTION mz_calculate_leisure_level(leisure_val text, sport_val text) +RETURNS SMALLINT AS $$ +BEGIN + RETURN CASE + WHEN leisure_val IN ('track') THEN + CASE + WHEN sport_val IN ('athletics', 'running', 'horse_racing', 'bmx', + 'disc_golf', 'cycling', 'ski_jumping', 'motor', 'karting', + 'obstacle_course', 'equestrian', 'alpine_slide', 'soap_box_derby', + 'mud_truck_racing', 'skiing', 'drag_racing', 'archery') THEN 14 + ELSE NULL + END + ELSE NULL + END; +END; +$$ LANGUAGE plpgsql IMMUTABLE; + +CREATE OR REPLACE FUNCTION mz_calculate_road_level(highway_val text, railway_val text, aeroway_val text, route_val text, service_val text, aerialway_val text, leisure_val text, sport_val text, way geometry) RETURNS SMALLINT AS $$ BEGIN RETURN LEAST( @@ -321,6 +344,9 @@ BEGIN ELSE NULL END, CASE WHEN aerialway_val IS NOT NULL THEN mz_calculate_aerialway_level(aerialway_val) + ELSE NULL END, + CASE WHEN leisure_val IS NOT NULL + THEN mz_calculate_leisure_level(leisure_val, sport_val) ELSE NULL END); END; $$ LANGUAGE plpgsql IMMUTABLE; diff --git a/data/triggers.sql b/data/triggers.sql index 505898468..180cf11ab 100644 --- a/data/triggers.sql +++ b/data/triggers.sql @@ -33,7 +33,7 @@ CREATE TRIGGER mz_trigger_point BEFORE INSERT OR UPDATE ON planet_osm_point FOR CREATE OR REPLACE FUNCTION mz_trigger_function_line() RETURNS TRIGGER AS $$ BEGIN - NEW.mz_road_level := mz_calculate_road_level(NEW."highway", NEW."railway", NEW."aeroway", NEW."route", NEW."service", NEW."aerialway", NEW."way"); + NEW.mz_road_level := mz_calculate_road_level(NEW."highway", NEW."railway", NEW."aeroway", NEW."route", NEW."service", NEW."aerialway", NEW."leisure", NEW."sport", NEW."way"); NEW.mz_transit_level := mz_calculate_transit_level(NEW."route"); RETURN NEW; END; diff --git a/queries/boundaries.jinja2 b/queries/boundaries.jinja2 index 54dbc1842..67f4c1397 100644 --- a/queries/boundaries.jinja2 +++ b/queries/boundaries.jinja2 @@ -105,6 +105,7 @@ SELECT NULL AS admin_level, NULL AS boundary_type, CASE WHEN barrier='retaining_wall' THEN 'retaining_wall' + WHEN man_made='snow_fence' THEN 'snow_fence' ELSE 'city_wall' END AS kind, {% filter geometry %}way{% endfilter %} AS __geometry__, @@ -120,6 +121,7 @@ WHERE barrier='city_wall' OR historic='citywalls' {% if zoom >= 15 %} OR barrier='retaining_wall' + OR man_made='snow_fence' {% endif %} ) diff --git a/queries/pois.jinja2 b/queries/pois.jinja2 index 297f751a1..9baa54265 100644 --- a/queries/pois.jinja2 +++ b/queries/pois.jinja2 @@ -9,8 +9,8 @@ SELECT transit_routes, %#tags AS tags, COALESCE("aerialway", "aeroway", "amenity", "barrier", "craft", "highway", "historic", - "leisure", "lock", "man_made", "natural", "office", "power", "railway", "shop", - "tourism", "waterway") AS kind + "leisure", "lock", "man_made", "natural", "office", "power", "railway", + "tags"->'rental', "shop", "tourism", "waterway") AS kind FROM ( diff --git a/queries/roads.jinja2 b/queries/roads.jinja2 index 1e4f348b3..c7ae4727b 100644 --- a/queries/roads.jinja2 +++ b/queries/roads.jinja2 @@ -65,6 +65,8 @@ SELECT NULL AS snowshoe, NULL AS symbol, NULL AS exit_to, + leisure, + sport, %#tags AS tags FROM planet_osm_line @@ -121,6 +123,8 @@ SELECT tags->'snowshoe' AS snowshoe, tags->'symbol' AS symbol, NULL AS exit_to, + leisure, + sport, %#tags AS tags FROM planet_osm_line @@ -173,6 +177,8 @@ SELECT NULL AS snowshoe, NULL AS symbol, tags->'exit_to' AS exit_to, + NULL AS leisure, + NULL AS sport, %#tags AS tags FROM planet_osm_point