From 6fb20ab650c244acf688991df9ac4ebc85d862ce Mon Sep 17 00:00:00 2001 From: Lukas Martinelli Date: Mon, 28 Nov 2016 16:03:42 +0000 Subject: [PATCH] Include country and state select direcdtly in layer func --- layers/place/city.sql | 3 +-- layers/place/country.sql | 11 ----------- layers/place/layer.sql | 24 ++++++++++++++++-------- layers/place/place.yaml | 2 -- layers/place/state.sql | 18 ------------------ 5 files changed, 17 insertions(+), 41 deletions(-) delete mode 100644 layers/place/country.sql delete mode 100644 layers/place/state.sql diff --git a/layers/place/city.sql b/layers/place/city.sql index d5304d3d..1695f312 100644 --- a/layers/place/city.sql +++ b/layers/place/city.sql @@ -40,6 +40,5 @@ RETURNS TABLE(osm_id bigint, geometry geometry, name text, name_en text, place c OR (zoom_level = 9 AND (gridrank <= 8 OR "rank" IS NOT NULL)) OR (zoom_level = 10 AND (gridrank <= 12 OR "rank" IS NOT NULL)) OR (zoom_level BETWEEN 11 AND 12 AND (gridrank <= 14 OR "rank" IS NOT NULL)) - OR (zoom_level >= 13) - ORDER BY "rank" ASC; + OR (zoom_level >= 13); $$ LANGUAGE SQL IMMUTABLE; diff --git a/layers/place/country.sql b/layers/place/country.sql deleted file mode 100644 index 3f276fa2..00000000 --- a/layers/place/country.sql +++ /dev/null @@ -1,11 +0,0 @@ - --- etldoc: layer_country[shape=record fillcolor=lightpink, style="rounded,filled", --- etldoc: label="layer_country | z0-z14_ " ] ; - --- etldoc: osm_country_point -> layer_country -CREATE OR REPLACE FUNCTION layer_country(bbox geometry, zoom_level int) -RETURNS TABLE(osm_id bigint, geometry geometry, name text, name_en text, "rank" int) AS $$ - SELECT osm_id, geometry, name, COALESCE(NULLIF(name_en, ''), name) AS name_en, "rank" FROM osm_country_point - WHERE geometry && bbox AND "rank" <= zoom_level AND name <> '' - ORDER BY "rank" ASC, length(name) ASC; -$$ LANGUAGE SQL IMMUTABLE; diff --git a/layers/place/layer.sql b/layers/place/layer.sql index a6871940..053a2601 100644 --- a/layers/place/layer.sql +++ b/layers/place/layer.sql @@ -2,10 +2,10 @@ -- etldoc: layer_place[shape=record fillcolor=lightpink, style="rounded,filled", -- etldoc: label="layer_place | z0-z14_ " ] ; --- etldoc: layer_continent -> layer_place --- etldoc: layer_country -> layer_place --- etldoc: layer_state -> layer_place --- etldoc: layer_city -> layer_place +-- etldoc: osm_continent_point -> layer_place +-- etldoc: osm_country_point -> layer_place +-- etldoc: osm_state_point -> layer_place +-- etldoc: layer_city -> layer_place CREATE OR REPLACE FUNCTION layer_place(bbox geometry, zoom_level int, pixel_width numeric) RETURNS TABLE(osm_id bigint, geometry geometry, name text, name_en text, class text, subclass text, "rank" int, capital INT) AS $$ @@ -16,17 +16,25 @@ RETURNS TABLE(osm_id bigint, geometry geometry, name text, name_en text, class t WHERE geometry && bbox AND zoom_level < 4 UNION ALL SELECT - osm_id, geometry, name, name_en, + osm_id, geometry, name, COALESCE(NULLIF(name_en, ''), name) AS name_en, 'country' AS class, 'country' AS subclass,"rank", NULL::int AS capital - FROM layer_country(bbox, zoom_level) + FROM osm_country_point + WHERE geometry && bbox AND "rank" <= zoom_level AND name <> '' UNION ALL SELECT - osm_id, geometry, name, name_en, + osm_id, geometry, name, COALESCE(NULLIF(name_en, ''), name) AS name_en, 'state' AS class, 'state' AS subclass, "rank", NULL::int AS capital - FROM layer_state(bbox, zoom_level) + FROM osm_state_point + WHERE geometry && bbox AND + name <> '' AND + ("rank" + 2 <= zoom_level) AND ( + zoom_level >= 5 OR + is_in_country IN ('United Kingdom', 'USA', 'Россия', 'Brasil', 'China', 'India') OR + is_in_country_code IN ('AU', 'CN', 'IN', 'BR', 'US')) UNION ALL SELECT osm_id, geometry, name, name_en, place_class(place::text) AS class, place::text AS subclass, "rank", capital FROM layer_city(bbox, zoom_level, pixel_width) + ORDER BY "rank" ASC $$ LANGUAGE SQL IMMUTABLE; diff --git a/layers/place/place.yaml b/layers/place/place.yaml index 02bedd7b..e1949bed 100644 --- a/layers/place/place.yaml +++ b/layers/place/place.yaml @@ -30,8 +30,6 @@ schema: - ./types.sql - ./class.sql - ./city.sql - - ./country.sql - - ./state.sql - ./merge_country_rank.sql - ./merge_city_rank.sql - ./merge_state_rank.sql diff --git a/layers/place/state.sql b/layers/place/state.sql deleted file mode 100644 index de11478e..00000000 --- a/layers/place/state.sql +++ /dev/null @@ -1,18 +0,0 @@ - --- etldoc: layer_state[shape=record fillcolor=lightpink, style="rounded,filled", --- etldoc: label="layer_state | z0-z14_ " ] ; - --- etldoc: osm_state_point -> layer_state - -CREATE OR REPLACE FUNCTION layer_state(bbox geometry, zoom_level int) -RETURNS TABLE(osm_id bigint, geometry geometry, name text, name_en text, "rank" int) AS $$ - SELECT osm_id, geometry, name, COALESCE(NULLIF(name_en, ''), name) AS name_en, "rank" - FROM osm_state_point - WHERE geometry && bbox AND - name <> '' AND - ("rank" + 2 <= zoom_level) AND ( - zoom_level >= 5 OR - is_in_country IN ('United Kingdom', 'USA', 'Россия', 'Brasil', 'China', 'India') OR - is_in_country_code IN ('AU', 'CN', 'IN', 'BR', 'US')) - ORDER BY "rank" ASC; -$$ LANGUAGE SQL IMMUTABLE;