Tweak place ranks
This commit is contained in:
parent
3f9f59dfe1
commit
52e133e126
@ -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"
|
SELECT osm_id, geometry, name, name_en, place, "rank"
|
||||||
FROM osm_city_point
|
FROM osm_city_point
|
||||||
WHERE geometry && bbox
|
WHERE geometry && bbox
|
||||||
AND ((zoom_level = 2 AND "rank" = 0)
|
AND ((zoom_level = 2 AND "rank" = 1)
|
||||||
OR (zoom_level BETWEEN 3 AND 7 AND "rank" < zoom_level)
|
OR (zoom_level BETWEEN 3 AND 7 AND "rank" <= zoom_level)
|
||||||
)
|
)
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT osm_id, geometry, name, name_en, place, "rank" FROM (
|
SELECT osm_id, geometry, name, name_en, place, "rank" FROM (
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
CREATE OR REPLACE FUNCTION layer_country(bbox geometry, zoom_level int)
|
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 $$
|
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
|
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;
|
ORDER BY "rank" ASC, length(name) ASC;
|
||||||
$$ LANGUAGE SQL IMMUTABLE;
|
$$ LANGUAGE SQL IMMUTABLE;
|
||||||
|
|||||||
@ -18,11 +18,9 @@ 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
|
||||||
-- Normalize both scalerank and labelrank into a ranking system from 1 to 10.
|
-- Move scalerank to range 1 to 10 and merge scalerank 5 with 6 since not enough cities
|
||||||
-- Scaleranks for NE populated place range from 0 to 8 and labelranks range from 0 to 10.
|
-- are in the scalerank 5 bucket
|
||||||
-- To give features with both ranks close to 0 a lower rank we increase the range from 1 to 9 and 1 to 11.
|
SET "rank" = CASE WHEN scalerank <= 5 THEN scalerank + 1 ELSE scalerank END
|
||||||
-- 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;
|
||||||
|
|
||||||
|
|||||||
@ -6,22 +6,21 @@ WITH important_country_point AS (
|
|||||||
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
|
||||||
-- because name matching is to difficult since OSM does not contain good
|
-- 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)
|
ST_Within(osm.geometry, ne.geom)
|
||||||
-- We leave out tiny countries
|
-- We leave out tiny countries
|
||||||
AND ne.scalerank <= 1
|
AND ne.scalerank <= 1
|
||||||
)
|
)
|
||||||
UPDATE osm_country_point AS osm
|
UPDATE osm_country_point AS osm
|
||||||
-- Normalize both scalerank and labelrank into a ranking system from 1 to 6
|
-- 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.
|
-- where the ranks are still distributed uniform enough across all countries
|
||||||
-- This means a max combined rank of 16 divided by 3 to get us uniform ranking from 1 to 6
|
SET "rank" = LEAST(6, CEILING((scalerank + labelrank)/2.0))
|
||||||
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" IS NULL;
|
||||||
|
|
||||||
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");
|
||||||
@ -12,9 +12,7 @@ WITH important_state_point AS (
|
|||||||
)
|
)
|
||||||
UPDATE osm_state_point AS osm
|
UPDATE osm_state_point AS osm
|
||||||
-- Normalize both scalerank and labelrank into a ranking system from 1 to 6.
|
-- 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.
|
SET "rank" = LEAST(6, CEILING((scalerank + labelrank + datarank)/3.0))
|
||||||
-- 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;
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,8 @@ layer:
|
|||||||
Countries, states and the most important cities all have a `rank` to boost their importance on the map.
|
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
|
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`. 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
|
buffer_size: 128
|
||||||
datasource:
|
datasource:
|
||||||
geometry_field: geometry
|
geometry_field: geometry
|
||||||
|
|||||||
@ -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 $$
|
RETURNS TABLE(osm_id bigint, geometry geometry, name text, name_en text, "rank" int) AS $$
|
||||||
SELECT osm_id, geometry, name, name_en, "rank"
|
SELECT osm_id, geometry, name, name_en, "rank"
|
||||||
FROM osm_state_point
|
FROM osm_state_point
|
||||||
WHERE geometry && bbox AND (
|
WHERE geometry && bbox AND
|
||||||
(zoom_level = 3 AND "rank" <= 1) OR
|
("rank" + 2 <= zoom_level) AND (
|
||||||
(zoom_level >= 4)
|
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;
|
ORDER BY "rank" ASC;
|
||||||
$$ LANGUAGE SQL IMMUTABLE;
|
$$ LANGUAGE SQL IMMUTABLE;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user