diff --git a/layers/place/README.md b/layers/place/README.md index a3ec52d..bd928b4 100644 --- a/layers/place/README.md +++ b/layers/place/README.md @@ -11,8 +11,12 @@ We suggest you use different font styles and sizes to create a text hierarchy. - **name**: The OSM [`name`](http://wiki.openstreetmap.org/wiki/Key:name) value of the POI. - **rank**: 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. +cities ranges from `1` to `10` for the most important cities and continues from `10` serially based +on the local importance of the city (derived from population and city class). +Use the `rank` field to build a text hierarchy. +The rank value is a combination of the Natural Earth `scalerank`, `labelrank` and `datarank` values for countries +and states and for cities consists out of a shifted Natural Earth `scalerank` combined with a local rank +within a grid for cities that do not have a Natural Earth `scalerank`. - **class**: Distinguish between `country`, `state` and other city classes like `city`, `town`, `village`, `hamlet`, `suburb`, `neighbourhood` or `isolated_dwelling`. Use this to separately style the different places according to their importance (usually country and state different diff --git a/layers/place/city.sql b/layers/place/city.sql index 8cf6f0e..5093eb6 100644 --- a/layers/place/city.sql +++ b/layers/place/city.sql @@ -7,14 +7,15 @@ RETURNS TABLE(osm_id bigint, geometry geometry, name text, name_en text, class c OR (zoom_level BETWEEN 3 AND 7 AND "rank" <= zoom_level) ) UNION ALL - SELECT osm_id, geometry, name, name_en, place, "rank" FROM ( - SELECT osm_id, geometry, name, name_en, place, "rank", - row_number() OVER ( - PARTITION BY LabelGrid(geometry, 150 * pixel_width) - ORDER BY place ASC NULLS LAST, - population DESC NULLS LAST, - length(name) DESC - ) AS gridrank + SELECT osm_id, geometry, name, name_en, place, COALESCE("rank", gridrank + 10) FROM ( + SELECT osm_id, geometry, name, name_en, place, "rank", + row_number() OVER ( + PARTITION BY LabelGrid(geometry, 150 * pixel_width) + ORDER BY "rank" ASC NULLS LAST, + place ASC NULLS LAST, + population DESC NULLS LAST, + length(name) ASC + )::int AS gridrank FROM osm_city_point WHERE geometry && bbox AND ((zoom_level BETWEEN 8 AND 9 AND place <= 'town'::city_class) @@ -23,7 +24,7 @@ RETURNS TABLE(osm_id bigint, geometry geometry, name text, name_en text, class c OR (zoom_level >= 14) ) ) AS ranked_places - WHERE (zoom_level = 8 AND gridrank <= 4) - OR (zoom_level BETWEEN 9 AND 12 AND gridrank <= 9) + WHERE (zoom_level = 8 AND (gridrank <= 4 OR "rank" IS NOT NULL)) + OR (zoom_level BETWEEN 9 AND 12 AND (gridrank <= 9 OR "rank" IS NOT NULL)) OR (zoom_level >= 13); $$ LANGUAGE SQL IMMUTABLE; diff --git a/layers/place/place.yaml b/layers/place/place.yaml index 98840b9..2ac875d 100644 --- a/layers/place/place.yaml +++ b/layers/place/place.yaml @@ -16,9 +16,12 @@ layer: rank: | 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. + cities ranges from `1` to `10` for the most important cities and continues from `10` serially based + on the local importance of the city (derived from population and city class). + Use the `rank` field to build a text hierarchy. 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. + and states and for cities consists out of a shifted Natural Earth `scalerank` combined with a local rank + within a grid for cities that do not have a Natural Earth `scalerank`. buffer_size: 128 datasource: geometry_field: geometry