Tweak place ranks

pull/24/head
lukasmartinelli 2016-10-29 14:29:41 +02:00
rodzic 3f9f59dfe1
commit 52e133e126
7 zmienionych plików z 18 dodań i 21 usunięć

Wyświetl plik

@ -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 (

Wyświetl plik

@ -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;

Wyświetl plik

@ -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;

Wyświetl plik

@ -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");

Wyświetl plik

@ -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;

Wyświetl plik

@ -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

Wyświetl plik

@ -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;