Make ranks more fine grained

This commit is contained in:
lukasmartinelli 2016-10-29 12:10:23 +02:00
parent 001e44ccd7
commit 3f9f59dfe1
5 changed files with 30 additions and 26 deletions

View File

@ -9,10 +9,10 @@ We suggest you use different font styles and sizes to create a text hierarchy.
- **name_en**: The english `name:en` value if available. - **name_en**: The english `name:en` value if available.
- **name**: The OSM [`name`](http://wiki.openstreetmap.org/wiki/Key:name) value of the POI. - **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` field ranging from `1` to `6` which - **rank**: Countries, states and the most important cities all have a `rank` to boost their importance on the map.
marks the importance of the feature. Less important places do not have a `rank`. The `rank` field for counries and states ranges from `1` to `6` while the `rank` field for
Use this to build a text hierarchy. The rank value originates from Natural Earth data and is either the cities ranges from `1` to `10`. Use the `rank` field to build a text hierarchy.
original `scalerank` for cities or the original `labelrank` for countries and states. The rank value is a combination of the Natural Earth `scalerank`, `labelrank` and `datarank` values.
- **class**: Distinguish between `country`, `state` and other city classes like - **class**: Distinguish between `country`, `state` and other city classes like
`city`, `town`, `village`, `hamlet`, `suburb`, `neighbourhood` or `isolated_dwelling`. `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 Use this to separately style the different places according to their importance (usually country and state different

View File

@ -1,5 +1,5 @@
WITH important_city_point AS ( WITH important_city_point AS (
SELECT osm.geometry, osm.osm_id, osm.name, osm.name_en, ne.scalerank SELECT osm.geometry, osm.osm_id, osm.name, osm.name_en, ne.scalerank, ne.labelrank
FROM ne_10m_populated_places AS ne, osm_city_point AS osm FROM ne_10m_populated_places AS ne, osm_city_point AS osm
WHERE WHERE
( (
@ -18,7 +18,11 @@ WITH important_city_point AS (
AND ST_DWithin(ne.geom, osm.geometry, 50000) AND ST_DWithin(ne.geom, osm.geometry, 50000)
) )
UPDATE osm_city_point AS osm UPDATE osm_city_point AS osm
SET "rank" = ne.scalerank -- 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)
FROM important_city_point AS ne FROM important_city_point AS ne
WHERE osm.osm_id = ne.osm_id; WHERE osm.osm_id = ne.osm_id;

View File

@ -1,5 +1,7 @@
ALTER TABLE osm_country_point DROP CONSTRAINT IF EXISTS osm_country_point_rank_constraint;
WITH important_country_point AS ( WITH important_country_point AS (
SELECT osm.geometry, osm.osm_id, osm.name, COALESCE(NULLIF(osm.name_en, ''), ne.name) AS name_en, ne.labelrank SELECT osm.geometry, osm.osm_id, osm.name, COALESCE(NULLIF(osm.name_en, ''), ne.name) AS name_en, ne.scalerank, ne.labelrank
FROM ne_10m_admin_0_countries AS ne, osm_country_point AS osm FROM ne_10m_admin_0_countries AS ne, osm_country_point AS osm
WHERE WHERE
-- We only match whether the point is within the Natural Earth polygon -- We only match whether the point is within the Natural Earth polygon
@ -10,17 +12,16 @@ WITH important_country_point AS (
AND ne.scalerank <= 1 AND ne.scalerank <= 1
) )
UPDATE osm_country_point AS osm UPDATE osm_country_point AS osm
-- We merge the labelrank not scalerank because it is more fine grained -- Normalize both scalerank and labelrank into a ranking system from 1 to 6
-- and allows styling more important countries bigger than others -- Scaleranks for NE countries range from 0 to 6 and labelranks range from 2 to 10.
SET "rank" = ne.labelrank -- 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)
FROM important_country_point AS ne FROM important_country_point AS ne
WHERE osm.osm_id = ne.osm_id; WHERE osm.osm_id = ne.osm_id;
UPDATE osm_country_point AS osm UPDATE osm_country_point AS osm
SET "rank" = 6 SET "rank" = 6
WHERE "rank" <= 0 OR "rank" > 6 OR "rank" IS NULL; WHERE "rank" < 0 OR "rank" > 6 OR "rank" IS NULL;
ALTER TABLE osm_country_point DROP CONSTRAINT IF EXISTS osm_country_point_rank_constraint;
ALTER TABLE osm_country_point ADD CONSTRAINT osm_country_point_rank_constraint CHECK("rank" BETWEEN 1 AND 6); 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");
CREATE INDEX IF NOT EXISTS osm_country_point_rank_idx ON osm_country_point("rank");

View File

@ -1,5 +1,7 @@
ALTER TABLE osm_state_point DROP CONSTRAINT IF EXISTS osm_state_point_rank_constraint;
WITH important_state_point AS ( WITH important_state_point AS (
SELECT osm.geometry, osm.osm_id, osm.name, COALESCE(NULLIF(osm.name_en, ''), ne.name) AS name_en, ne.scalerank, ne.labelrank SELECT osm.geometry, osm.osm_id, osm.name, COALESCE(NULLIF(osm.name_en, ''), ne.name) AS name_en, ne.scalerank, ne.labelrank, ne.datarank
FROM ne_10m_admin_1_states_provinces_shp AS ne, osm_state_point AS osm FROM ne_10m_admin_1_states_provinces_shp AS ne, osm_state_point AS osm
WHERE WHERE
-- We only match whether the point is within the Natural Earth polygon -- We only match whether the point is within the Natural Earth polygon
@ -9,17 +11,14 @@ WITH important_state_point AS (
AND ne.scalerank <= 3 AND ne.labelrank <= 2 AND ne.scalerank <= 3 AND ne.labelrank <= 2
) )
UPDATE osm_state_point AS osm UPDATE osm_state_point AS osm
-- We merge the labelrank not scalerank because it is more fine grained -- Normalize both scalerank and labelrank into a ranking system from 1 to 6.
SET "rank" = ne.labelrank -- 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)
FROM important_state_point AS ne FROM important_state_point AS ne
WHERE osm.osm_id = ne.osm_id; WHERE osm.osm_id = ne.osm_id;
UPDATE osm_state_point AS osm
SET "rank" = 6
WHERE "rank" <= 0 OR "rank" > 6;
DELETE FROM osm_state_point WHERE "rank" IS NULL; DELETE FROM osm_state_point WHERE "rank" IS NULL;
ALTER TABLE osm_state_point DROP CONSTRAINT IF EXISTS osm_state_point_rank_constraint;
ALTER TABLE osm_state_point ADD CONSTRAINT osm_state_point_rank_constraint CHECK("rank" BETWEEN 1 AND 6); ALTER TABLE osm_state_point ADD CONSTRAINT osm_state_point_rank_constraint CHECK("rank" BETWEEN 1 AND 6);
CREATE INDEX IF NOT EXISTS osm_state_point_rank_idx ON osm_state_point("rank"); CREATE INDEX IF NOT EXISTS osm_state_point_rank_idx ON osm_state_point("rank");

View File

@ -14,10 +14,10 @@ layer:
Use this to separately style the different places according to their importance (usually country and state different Use this to separately style the different places according to their importance (usually country and state different
than cities). than cities).
rank: | rank: |
Countries, states and the most important cities all have a `rank` field ranging from `1` to `6` which Countries, states and the most important cities all have a `rank` to boost their importance on the map.
marks the importance of the feature. Less important places do not have a `rank`. The `rank` field for counries and states ranges from `1` to `6` while the `rank` field for
Use this to build a text hierarchy. The rank value originates from Natural Earth data and is either the cities ranges from `1` to `10`. Use the `rank` field to build a text hierarchy.
original `scalerank` for cities or the original `labelrank` for countries and states. The rank value is a combination of the Natural Earth `scalerank`, `labelrank` and `datarank` values.
buffer_size: 128 buffer_size: 128
datasource: datasource:
geometry_field: geometry geometry_field: geometry