diff --git a/layers/place/city.sql b/layers/place/city.sql index 902b64b..8cf6f0e 100644 --- a/layers/place/city.sql +++ b/layers/place/city.sql @@ -3,8 +3,8 @@ RETURNS TABLE(osm_id bigint, geometry geometry, name text, name_en text, class c SELECT osm_id, geometry, name, name_en, place, "rank" FROM osm_city_point WHERE geometry && bbox - AND ((zoom_level = 2 AND "rank" = 0) - OR (zoom_level BETWEEN 3 AND 7 AND "rank" < zoom_level) + AND ((zoom_level = 2 AND "rank" = 1) + OR (zoom_level BETWEEN 3 AND 7 AND "rank" <= zoom_level) ) UNION ALL SELECT osm_id, geometry, name, name_en, place, "rank" FROM ( diff --git a/layers/place/country.sql b/layers/place/country.sql index 805b90d..82511b6 100644 --- a/layers/place/country.sql +++ b/layers/place/country.sql @@ -1,6 +1,6 @@ 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, name_en, "rank" FROM osm_country_point - WHERE geometry && bbox AND "rank" <= (zoom_level + 2) + WHERE geometry && bbox AND "rank" <= zoom_level ORDER BY "rank" ASC, length(name) ASC; $$ LANGUAGE SQL IMMUTABLE; diff --git a/layers/place/merge_city_rank.sql b/layers/place/merge_city_rank.sql index 0b98598..8a08b5d 100644 --- a/layers/place/merge_city_rank.sql +++ b/layers/place/merge_city_rank.sql @@ -18,11 +18,9 @@ WITH important_city_point AS ( AND ST_DWithin(ne.geom, osm.geometry, 50000) ) UPDATE osm_city_point AS osm --- Normalize both scalerank and labelrank into a ranking system from 1 to 10. --- Scaleranks for NE populated place range from 0 to 8 and labelranks range from 0 to 10. --- To give features with both ranks close to 0 a lower rank we increase the range from 1 to 9 and 1 to 11. --- This means a max combined rank of 20 divided by 2 to get us uniform ranking from 1 to 10 -SET "rank" = CEILING((ne.scalerank + 1 + ne.labelrank + 1)/2.0) +-- Move scalerank to range 1 to 10 and merge scalerank 5 with 6 since not enough cities +-- are in the scalerank 5 bucket +SET "rank" = CASE WHEN scalerank <= 5 THEN scalerank + 1 ELSE scalerank END FROM important_city_point AS ne WHERE osm.osm_id = ne.osm_id; diff --git a/layers/place/merge_country_rank.sql b/layers/place/merge_country_rank.sql index ac1bfd5..898bb96 100644 --- a/layers/place/merge_country_rank.sql +++ b/layers/place/merge_country_rank.sql @@ -6,22 +6,21 @@ WITH important_country_point AS ( WHERE -- We only match whether the point is within the Natural Earth polygon -- because name matching is to difficult since OSM does not contain good - -- enough coverage of ISO codes + -- enough coverage of ISO codesy ST_Within(osm.geometry, ne.geom) -- We leave out tiny countries AND ne.scalerank <= 1 ) UPDATE osm_country_point AS osm -- Normalize both scalerank and labelrank into a ranking system from 1 to 6 --- Scaleranks for NE countries range from 0 to 6 and labelranks range from 2 to 10. --- This means a max combined rank of 16 divided by 3 to get us uniform ranking from 1 to 6 -SET "rank" = CEILING((scalerank + labelrank)/3.0) +-- where the ranks are still distributed uniform enough across all countries +SET "rank" = LEAST(6, CEILING((scalerank + labelrank)/2.0)) FROM important_country_point AS ne WHERE osm.osm_id = ne.osm_id; UPDATE osm_country_point AS osm SET "rank" = 6 -WHERE "rank" < 0 OR "rank" > 6 OR "rank" IS NULL; +WHERE "rank" IS NULL; ALTER TABLE osm_country_point ADD CONSTRAINT osm_country_point_rank_constraint CHECK("rank" BETWEEN 1 AND 6); CREATE INDEX IF NOT EXISTS osm_country_point_rank_idx ON osm_country_point("rank"); \ No newline at end of file diff --git a/layers/place/merge_state_rank.sql b/layers/place/merge_state_rank.sql index 20ebc8b..51181ba 100644 --- a/layers/place/merge_state_rank.sql +++ b/layers/place/merge_state_rank.sql @@ -12,9 +12,7 @@ WITH important_state_point AS ( ) UPDATE osm_state_point AS osm -- Normalize both scalerank and labelrank into a ranking system from 1 to 6. --- Scaleranks for NE states range from 2 to 11 and labelranks range from 0 to 20 and dataranks from 1 to 11. --- This means a max combined rank of 42 divided by 7 to get us uniform ranking from 1 to 6 -SET "rank" = CEILING((scalerank + labelrank + datarank)/7.0) +SET "rank" = LEAST(6, CEILING((scalerank + labelrank + datarank)/3.0)) FROM important_state_point AS ne WHERE osm.osm_id = ne.osm_id; diff --git a/layers/place/place.yaml b/layers/place/place.yaml index 789ad18..98840b9 100644 --- a/layers/place/place.yaml +++ b/layers/place/place.yaml @@ -17,7 +17,8 @@ layer: Countries, states and the most important cities all have a `rank` to boost their importance on the map. The `rank` field for counries and states ranges from `1` to `6` while the `rank` field for cities ranges from `1` to `10`. Use the `rank` field to build a text hierarchy. - The rank value is a combination of the Natural Earth `scalerank`, `labelrank` and `datarank` values. + The rank value is a combination of the Natural Earth `scalerank`, `labelrank` and `datarank` values for countries + and states and a shifted Natural Earth `scalerank` for cities. buffer_size: 128 datasource: geometry_field: geometry diff --git a/layers/place/state.sql b/layers/place/state.sql index 96c90d8..3ed1b92 100644 --- a/layers/place/state.sql +++ b/layers/place/state.sql @@ -2,9 +2,10 @@ 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, name_en, "rank" FROM osm_state_point - WHERE geometry && bbox AND ( - (zoom_level = 3 AND "rank" <= 1) OR - (zoom_level >= 4) - ) + WHERE geometry && bbox 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;