Merge scaleranks for countries and states
This commit is contained in:
parent
4976ebba8e
commit
6513ed1633
@ -4,11 +4,11 @@ name_field: &name
|
|||||||
type: string
|
type: string
|
||||||
name_en_field: &name_en
|
name_en_field: &name_en
|
||||||
name: name_en
|
name: name_en
|
||||||
key: name_en
|
key: name:en
|
||||||
type: string
|
type: string
|
||||||
scalerank_field: &scalerank
|
rank_field: &rank
|
||||||
name: scalerank
|
name: rank
|
||||||
key: scalerank
|
key: rank
|
||||||
type: integer
|
type: integer
|
||||||
tables:
|
tables:
|
||||||
country_point:
|
country_point:
|
||||||
@ -20,13 +20,7 @@ tables:
|
|||||||
type: geometry
|
type: geometry
|
||||||
- *name
|
- *name
|
||||||
- *name_en
|
- *name_en
|
||||||
- name: name_int
|
- *rank
|
||||||
key: int_name
|
|
||||||
type: string
|
|
||||||
- name: country_code_fips
|
|
||||||
key: country_code_fips
|
|
||||||
type: string
|
|
||||||
- *scalerank
|
|
||||||
filters:
|
filters:
|
||||||
exclude_tags:
|
exclude_tags:
|
||||||
- [ "name", "__nil__" ]
|
- [ "name", "__nil__" ]
|
||||||
@ -48,13 +42,10 @@ tables:
|
|||||||
- name: is_in_country_code
|
- name: is_in_country_code
|
||||||
key: is_in:country_code
|
key: is_in:country_code
|
||||||
type: string
|
type: string
|
||||||
- name: name_abbreviation
|
|
||||||
key: name:abbreviation
|
|
||||||
type: string
|
|
||||||
- name: ref
|
- name: ref
|
||||||
key: ref
|
key: ref
|
||||||
type: string
|
type: string
|
||||||
- *scalerank
|
- *rank
|
||||||
filters:
|
filters:
|
||||||
exclude_tags:
|
exclude_tags:
|
||||||
- [ "name", "__nil__" ]
|
- [ "name", "__nil__" ]
|
||||||
@ -76,7 +67,7 @@ tables:
|
|||||||
- key: population
|
- key: population
|
||||||
name: population
|
name: population
|
||||||
type: integer
|
type: integer
|
||||||
- *scalerank
|
- *rank
|
||||||
filters:
|
filters:
|
||||||
exclude_tags:
|
exclude_tags:
|
||||||
- [ "name", "__nil__" ]
|
- [ "name", "__nil__" ]
|
||||||
|
|||||||
@ -1,25 +1,3 @@
|
|||||||
WITH important_country_point AS (
|
|
||||||
SELECT osm.geometry, osm.osm_id, osm.name, osm.name_en, ne.scalerank
|
|
||||||
FROM ne_10m_admin_0_countries AS ne, osm_country_point AS osm
|
|
||||||
WHERE
|
|
||||||
(
|
|
||||||
ne.name ILIKE osm.name OR
|
|
||||||
ne.name ILIKE osm.name_en OR
|
|
||||||
ne.adm0_a3 ILIKE osm.country_code_fips
|
|
||||||
)
|
|
||||||
AND ST_Within(osm.geometry, ne.geom)
|
|
||||||
)
|
|
||||||
UPDATE osm_country_point AS osm
|
|
||||||
SET scalerank = ne.scalerank
|
|
||||||
FROM important_country_point AS ne
|
|
||||||
WHERE osm.osm_id = ne.osm_id;
|
|
||||||
|
|
||||||
DELETE FROM osm_state_point
|
|
||||||
WHERE is_in_country IN ('United Kingdom', 'USA', 'Россия', 'Brasil', 'China', 'India')
|
|
||||||
OR is_in_country_code IN ('AU', 'CN', 'IN', 'BR', 'US');
|
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS osm_country_point_scalerank_idx ON osm_country_point(scalerank);
|
|
||||||
|
|
||||||
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
|
||||||
FROM ne_10m_populated_places AS ne, osm_city_point AS osm
|
FROM ne_10m_populated_places AS ne, osm_city_point AS osm
|
||||||
26
layers/place/merge_country_rank.sql
Normal file
26
layers/place/merge_country_rank.sql
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
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
|
||||||
|
FROM ne_10m_admin_0_countries AS ne, osm_country_point AS osm
|
||||||
|
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
|
||||||
|
ST_Within(osm.geometry, ne.geom)
|
||||||
|
-- We leave out tiny countries
|
||||||
|
AND ne.scalerank <= 1
|
||||||
|
)
|
||||||
|
UPDATE osm_country_point AS osm
|
||||||
|
-- We merge the labelrank not scalerank because it is more fine grained
|
||||||
|
-- and allows styling more important countries bigger than others
|
||||||
|
SET "rank" = ne.labelrank
|
||||||
|
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;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS osm_country_point_rank_idx ON osm_country_point("rank");
|
||||||
25
layers/place/merge_state_rank.sql
Normal file
25
layers/place/merge_state_rank.sql
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
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
|
||||||
|
FROM ne_10m_admin_1_states_provinces_shp AS ne, osm_state_point AS osm
|
||||||
|
WHERE
|
||||||
|
-- We only match whether the point is within the Natural Earth polygon
|
||||||
|
-- because name matching is difficult
|
||||||
|
ST_Within(osm.geometry, ne.geom)
|
||||||
|
-- We leave out leess important states
|
||||||
|
AND ne.scalerank <= 3 AND ne.labelrank <= 2
|
||||||
|
)
|
||||||
|
UPDATE osm_state_point AS osm
|
||||||
|
-- We merge the labelrank not scalerank because it is more fine grained
|
||||||
|
SET "rank" = ne.labelrank
|
||||||
|
FROM important_state_point AS ne
|
||||||
|
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;
|
||||||
|
|
||||||
|
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);
|
||||||
|
CREATE INDEX IF NOT EXISTS osm_state_point_rank_idx ON osm_state_point("rank");
|
||||||
@ -18,7 +18,9 @@ schema:
|
|||||||
- ./city.sql
|
- ./city.sql
|
||||||
- ./country.sql
|
- ./country.sql
|
||||||
- ./state.sql
|
- ./state.sql
|
||||||
- ./merge_scalerank.sql
|
- ./merge_country_rank.sql
|
||||||
|
- ./merge_city_rank.sql
|
||||||
|
- ./merge_state_rank.sql
|
||||||
- ./place.sql
|
- ./place.sql
|
||||||
datasources:
|
datasources:
|
||||||
- type: imposm3
|
- type: imposm3
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user