diff --git a/layers/boundary/boundary.sql b/layers/boundary/boundary.sql index e95de1f2..3d242645 100644 --- a/layers/boundary/boundary.sql +++ b/layers/boundary/boundary.sql @@ -632,7 +632,7 @@ FROM osm_border_linestring_gen_z13 ); -- etldoc: layer_boundary[shape=record fillcolor=lightpink, style="rounded,filled", --- etldoc: label=" layer_boundary | z0 | z1 | z2 | z3 | z4 | z5 | z6 | z7 | z8 | z9 | z10 | z11 | z12| z13+"] +-- etldoc: label=" layer_boundary | z0 | z1 | z2 | z3 | z4 | z5 | z6 | z7 | z8 | z9 | z10 | z11 | z12| z13| z14+"] CREATE OR REPLACE FUNCTION layer_boundary(bbox geometry, zoom_level int) RETURNS TABLE ( @@ -643,11 +643,14 @@ CREATE OR REPLACE FUNCTION layer_boundary(bbox geometry, zoom_level int) disputed int, disputed_name text, claimed_by text, - maritime int + maritime int, + class text, + name text, + tags hstore ) AS $$ -SELECT geometry, admin_level, adm0_l, adm0_r, disputed::int, disputed_name, claimed_by, maritime::int +SELECT geometry, admin_level, adm0_l, adm0_r, disputed::int, disputed_name, claimed_by, maritime::int, NULL::text, NULL::text, NULL::hstore FROM ( -- etldoc: boundary_z0 -> layer_boundary:z0 SELECT * @@ -732,7 +735,134 @@ FROM ( FROM boundary_z13 WHERE geometry && bbox AND zoom_level >= 13 - ) AS zoom_levels; + ) AS segment_zoom_levels + +UNION ALL + +SELECT geometry, NULL::int, NULL::text, NULL::text, NULL::int, NULL::text, NULL::text, NULL::int, class, name, tags +FROM ( + + -- etldoc: osm_boundary_polygon_gen_z4 -> layer_boundary:z4 + SELECT geometry, + boundary AS class, + name, + tags + FROM osm_boundary_polygon_gen_z4 + WHERE zoom_level = 4 + AND geometry && bbox + + UNION ALL + + -- etldoc: osm_boundary_polygon_gen_z5 -> layer_boundary:z5 + SELECT geometry, + boundary AS class, + name, + tags + FROM osm_boundary_polygon_gen_z5 + WHERE zoom_level = 5 + AND geometry && bbox + + UNION ALL + + -- etldoc: osm_boundary_polygon_gen_z6 -> layer_boundary:z6 + SELECT geometry, + boundary AS class, + name, + tags + FROM osm_boundary_polygon_gen_z6 + WHERE zoom_level = 6 + AND geometry && bbox + + UNION ALL + + -- etldoc: osm_boundary_polygon_gen_z7 -> layer_boundary:z7 + SELECT geometry, + boundary AS class, + name, + tags + FROM osm_boundary_polygon_gen_z7 + WHERE zoom_level = 7 + AND geometry && bbox + + UNION ALL + + -- etldoc: osm_boundary_polygon_gen_z8 -> layer_boundary:z8 + SELECT geometry, + boundary AS class, + name, + tags + FROM osm_boundary_polygon_gen_z8 + WHERE zoom_level = 8 + AND geometry && bbox + + UNION ALL + + -- etldoc: osm_boundary_polygon_gen_z9 -> layer_boundary:z9 + SELECT geometry, + boundary AS class, + name, + tags + FROM osm_boundary_polygon_gen_z9 + WHERE zoom_level = 9 + AND geometry && bbox + + UNION ALL + + -- etldoc: osm_boundary_polygon_gen_z10 -> layer_boundary:z10 + SELECT geometry, + boundary AS class, + name, + tags + FROM osm_boundary_polygon_gen_z10 + WHERE zoom_level = 10 + AND geometry && bbox + + UNION ALL + + -- etldoc: osm_boundary_polygon_gen_z11 -> layer_boundary:z11 + SELECT geometry, + boundary AS class, + name, + tags + FROM osm_boundary_polygon_gen_z11 + WHERE zoom_level = 11 + AND geometry && bbox + + UNION ALL + + -- etldoc: osm_boundary_polygon_gen_z12 -> layer_boundary:z12 + SELECT geometry, + boundary AS class, + name, + tags + FROM osm_boundary_polygon_gen_z12 + WHERE zoom_level = 12 + AND geometry && bbox + + UNION ALL + + -- etldoc: osm_boundary_polygon_gen_z13 -> layer_boundary:z13 + SELECT geometry, + boundary AS class, + name, + tags + FROM osm_boundary_polygon_gen_z13 + WHERE zoom_level = 13 + AND geometry && bbox + + UNION ALL + + -- etldoc: osm_boundary_polygon -> layer_boundary:z14 + SELECT geometry, + boundary AS class, + name, + tags + FROM osm_boundary_polygon + WHERE zoom_level = 14 + AND geometry && bbox + + ) AS area_zoom_levels + $$ LANGUAGE SQL STABLE -- STRICT PARALLEL SAFE; diff --git a/layers/boundary/boundary.yaml b/layers/boundary/boundary.yaml index 78f89550..636cb9e9 100644 --- a/layers/boundary/boundary.yaml +++ b/layers/boundary/boundary.yaml @@ -9,13 +9,17 @@ layer: - ne_50m_admin_0_boundary_lines_land - ne_110m_admin_0_boundary_lines_land description: | - Contains administrative boundaries as linestrings. + Contains administrative boundaries as linestrings and aboriginal lands as polygons. Until z4 [Natural Earth data](http://www.naturalearthdata.com/downloads/) is used after which OSM boundaries ([`boundary=administrative`](http://wiki.openstreetmap.org/wiki/Tag:boundary%3Dadministrative)) are present from z5 to z14 (also for maritime boundaries with `admin_level <= 2` at z4). OSM data contains several [`admin_level`](http://wiki.openstreetmap.org/wiki/Tag:boundary%3Dadministrative#admin_level) but for most styles it makes sense to just style `admin_level=2` and `admin_level=4`. fields: + class: + description: | + Use the **class** to differentiate between different kinds of boundaries. The class for `boundary=aboriginal_lands` is `aboriginal_lands`. + name: The OSM [`name`](http://wiki.openstreetmap.org/wiki/Key:name) value (area features only). admin_level: | OSM [admin_level](http://wiki.openstreetmap.org/wiki/Tag:boundary%3Dadministrative#admin_level) indicating the level of importance of this boundary. @@ -58,8 +62,9 @@ layer: buffer_size: 4 datasource: geometry_field: geometry - query: (SELECT geometry, admin_level, adm0_l, adm0_r, disputed, disputed_name, claimed_by, maritime FROM layer_boundary(!bbox!, z(!scale_denominator!))) AS t + query: (SELECT geometry, admin_level, adm0_l, adm0_r, disputed, disputed_name, claimed_by, maritime, class, name, {name_languages} FROM layer_boundary(!bbox!, z(!scale_denominator!))) AS t schema: + - ./update_boundary_polygon.sql - ./boundary_name.sql - ./boundary.sql datasources: diff --git a/layers/boundary/etl_diagram.png b/layers/boundary/etl_diagram.png index f45adcfd..50848a08 100644 Binary files a/layers/boundary/etl_diagram.png and b/layers/boundary/etl_diagram.png differ diff --git a/layers/boundary/mapping.yaml b/layers/boundary/mapping.yaml index dda9fa4f..bb2de21b 100644 --- a/layers/boundary/mapping.yaml +++ b/layers/boundary/mapping.yaml @@ -4,6 +4,67 @@ generalized_tables: source: border_linestring sql_filter: ST_GeometryType(geometry) = 'ST_LineString' AND (disputed OR dispute OR border_status = 'disputed' OR disputed_by <> '') AND admin_level = 2 + # etldoc: osm_boundary_polygon_gen_z5 -> osm_boundary_polygon_gen_z4 + boundary_polygon_gen_z4: + source: boundary_polygon_gen_z5 + sql_filter: area>power(ZRES3,2) + tolerance: ZRES4 + + # etldoc: osm_boundary_polygon_gen_z6 -> osm_boundary_polygon_gen_z5 + boundary_polygon_gen_z5: + source: boundary_polygon_gen_z6 + sql_filter: area>power(ZRES4,2) + tolerance: ZRES5 + + # etldoc: osm_boundary_polygon_gen_z7 -> osm_boundary_polygon_gen_z6 + boundary_polygon_gen_z6: + source: boundary_polygon_gen_z7 + sql_filter: area>power(ZRES5,2) + tolerance: ZRES6 + + # etldoc: osm_boundary_polygon_gen_z8 -> osm_boundary_polygon_gen_z7 + boundary_polygon_gen_z7: + source: boundary_polygon_gen_z8 + sql_filter: area>power(ZRES6,2) + tolerance: ZRES7 + + # etldoc: osm_boundary_polygon_gen_z9 -> osm_boundary_polygon_gen_z8 + boundary_polygon_gen_z8: + source: boundary_polygon_gen_z9 + sql_filter: area>power(ZRES7,2) + tolerance: ZRES8 + + # etldoc: osm_boundary_polygon_gen_z10 -> osm_boundary_polygon_gen_z9 + boundary_polygon_gen_z9: + source: boundary_polygon_gen_z10 + sql_filter: area>power(ZRES8,2) + tolerance: ZRES9 + + # etldoc: osm_boundary_polygon_gen_z11 -> osm_boundary_polygon_gen_z10 + boundary_polygon_gen_z10: + source: boundary_polygon_gen_z11 + sql_filter: area>power(ZRES9,2) + tolerance: ZRES10 + + # etldoc: osm_boundary_polygon_gen_z12 -> osm_boundary_polygon_gen_z11 + boundary_polygon_gen_z11: + source: boundary_polygon_gen_z12 + sql_filter: area>power(ZRES10,2) + tolerance: ZRES11 + + # etldoc: osm_boundary_polygon_gen_z13 -> osm_boundary_polygon_gen_z12 + boundary_polygon_gen_z12: + source: boundary_polygon_gen_z13 + sql_filter: area>power(ZRES11,2) + tolerance: ZRES12 + + # etldoc: osm_boundary_polygon -> osm_boundary_polygon_gen_z13 + boundary_polygon_gen_z13: + source: boundary_polygon + sql_filter: area>power(ZRES12,2) AND ST_IsValid(geometry) + tolerance: ZRES13 + + tables: # etldoc: imposm3 -> osm_border_linestring border_linestring: @@ -71,3 +132,29 @@ tables: - dispute boundary_type: - maritime + + # etldoc: imposm3 -> osm_boundary_polygon + boundary_polygon: + type: polygon + filters: + require: + type: [boundary] + boundary: [aboriginal_lands] + columns: + - name: osm_id + type: id + - name: geometry + type: validated_geometry + - name: name + key: name + type: string + - name: tags + type: hstore_tags + - name: boundary + key: boundary + type: string + - name: area + type: area + mapping: + boundary: + - aboriginal_lands diff --git a/layers/boundary/mapping_diagram.png b/layers/boundary/mapping_diagram.png index db85cc42..8ec79b64 100644 Binary files a/layers/boundary/mapping_diagram.png and b/layers/boundary/mapping_diagram.png differ diff --git a/layers/boundary/update_boundary_polygon.sql b/layers/boundary/update_boundary_polygon.sql new file mode 100644 index 00000000..bfe44695 --- /dev/null +++ b/layers/boundary/update_boundary_polygon.sql @@ -0,0 +1,221 @@ +ALTER TABLE osm_boundary_polygon + ADD COLUMN IF NOT EXISTS geometry_point geometry; +ALTER TABLE osm_boundary_polygon_gen_z13 + ADD COLUMN IF NOT EXISTS geometry_point geometry; +ALTER TABLE osm_boundary_polygon_gen_z12 + ADD COLUMN IF NOT EXISTS geometry_point geometry; +ALTER TABLE osm_boundary_polygon_gen_z11 + ADD COLUMN IF NOT EXISTS geometry_point geometry; +ALTER TABLE osm_boundary_polygon_gen_z10 + ADD COLUMN IF NOT EXISTS geometry_point geometry; +ALTER TABLE osm_boundary_polygon_gen_z9 + ADD COLUMN IF NOT EXISTS geometry_point geometry; +ALTER TABLE osm_boundary_polygon_gen_z8 + ADD COLUMN IF NOT EXISTS geometry_point geometry; +ALTER TABLE osm_boundary_polygon_gen_z7 + ADD COLUMN IF NOT EXISTS geometry_point geometry; +ALTER TABLE osm_boundary_polygon_gen_z6 + ADD COLUMN IF NOT EXISTS geometry_point geometry; +ALTER TABLE osm_boundary_polygon_gen_z5 + ADD COLUMN IF NOT EXISTS geometry_point geometry; + +DROP TRIGGER IF EXISTS update_row ON osm_boundary_polygon; +DROP TRIGGER IF EXISTS update_row ON osm_boundary_polygon_gen_z13; +DROP TRIGGER IF EXISTS update_row ON osm_boundary_polygon_gen_z12; +DROP TRIGGER IF EXISTS update_row ON osm_boundary_polygon_gen_z11; +DROP TRIGGER IF EXISTS update_row ON osm_boundary_polygon_gen_z10; +DROP TRIGGER IF EXISTS update_row ON osm_boundary_polygon_gen_z9; +DROP TRIGGER IF EXISTS update_row ON osm_boundary_polygon_gen_z8; +DROP TRIGGER IF EXISTS update_row ON osm_boundary_polygon_gen_z7; +DROP TRIGGER IF EXISTS update_row ON osm_boundary_polygon_gen_z6; +DROP TRIGGER IF EXISTS update_row ON osm_boundary_polygon_gen_z5; +DROP TRIGGER IF EXISTS trigger_flag ON osm_boundary_polygon; +DROP TRIGGER IF EXISTS trigger_refresh ON boundary_polygon.updates; + +-- etldoc: osm_boundary_polygon -> osm_boundary_polygon +-- etldoc: osm_boundary_polygon_gen_z13 -> osm_boundary_polygon_gen_z13 +-- etldoc: osm_boundary_polygon_gen_z12 -> osm_boundary_polygon_gen_z12 +-- etldoc: osm_boundary_polygon_gen_z11 -> osm_boundary_polygon_gen_z11 +-- etldoc: osm_boundary_polygon_gen_z10 -> osm_boundary_polygon_gen_z10 +-- etldoc: osm_boundary_polygon_gen_z9 -> osm_boundary_polygon_gen_z9 +-- etldoc: osm_boundary_polygon_gen_z8 -> osm_boundary_polygon_gen_z8 +-- etldoc: osm_boundary_polygon_gen_z7 -> osm_boundary_polygon_gen_z7 +-- etldoc: osm_boundary_polygon_gen_z6 -> osm_boundary_polygon_gen_z6 +-- etldoc: osm_boundary_polygon_gen_z5 -> osm_boundary_polygon_gen_z5 +CREATE OR REPLACE FUNCTION update_osm_boundary_polygon() RETURNS void AS +$$ +BEGIN + UPDATE osm_boundary_polygon + SET tags = update_tags(tags, geometry), + geometry_point = st_centroid(geometry); + + UPDATE osm_boundary_polygon_gen_z13 + SET tags = update_tags(tags, geometry), + geometry_point = st_centroid(geometry); + + UPDATE osm_boundary_polygon_gen_z12 + SET tags = update_tags(tags, geometry), + geometry_point = st_centroid(geometry); + + UPDATE osm_boundary_polygon_gen_z11 + SET tags = update_tags(tags, geometry), + geometry_point = st_centroid(geometry); + + UPDATE osm_boundary_polygon_gen_z10 + SET tags = update_tags(tags, geometry), + geometry_point = st_centroid(geometry); + + UPDATE osm_boundary_polygon_gen_z9 + SET tags = update_tags(tags, geometry), + geometry_point = st_centroid(geometry); + + UPDATE osm_boundary_polygon_gen_z8 + SET tags = update_tags(tags, geometry), + geometry_point = st_centroid(geometry); + + UPDATE osm_boundary_polygon_gen_z7 + SET tags = update_tags(tags, geometry), + geometry_point = st_centroid(geometry); + + UPDATE osm_boundary_polygon_gen_z6 + SET tags = update_tags(tags, geometry), + geometry_point = st_centroid(geometry); + + UPDATE osm_boundary_polygon_gen_z5 + SET tags = update_tags(tags, geometry), + geometry_point = st_centroid(geometry); + +END; +$$ LANGUAGE plpgsql; + +SELECT update_osm_boundary_polygon(); +CREATE INDEX IF NOT EXISTS osm_boundary_polygon_point_geom_idx ON osm_boundary_polygon USING gist (geometry_point); +CREATE INDEX IF NOT EXISTS osm_boundary_polygon_gen_z13_point_geom_idx ON osm_boundary_polygon_gen_z13 USING gist (geometry_point); +CREATE INDEX IF NOT EXISTS osm_boundary_polygon_gen_z12_point_geom_idx ON osm_boundary_polygon_gen_z12 USING gist (geometry_point); +CREATE INDEX IF NOT EXISTS osm_boundary_polygon_gen_z11_point_geom_idx ON osm_boundary_polygon_gen_z11 USING gist (geometry_point); +CREATE INDEX IF NOT EXISTS osm_boundary_polygon_gen_z10_point_geom_idx ON osm_boundary_polygon_gen_z10 USING gist (geometry_point); +CREATE INDEX IF NOT EXISTS osm_boundary_polygon_gen_z9_point_geom_idx ON osm_boundary_polygon_gen_z9 USING gist (geometry_point); +CREATE INDEX IF NOT EXISTS osm_boundary_polygon_gen_z8_point_geom_idx ON osm_boundary_polygon_gen_z8 USING gist (geometry_point); +CREATE INDEX IF NOT EXISTS osm_boundary_polygon_gen_z7_point_geom_idx ON osm_boundary_polygon_gen_z7 USING gist (geometry_point); +CREATE INDEX IF NOT EXISTS osm_boundary_polygon_gen_z6_point_geom_idx ON osm_boundary_polygon_gen_z6 USING gist (geometry_point); +CREATE INDEX IF NOT EXISTS osm_boundary_polygon_gen_z5_point_geom_idx ON osm_boundary_polygon_gen_z5 USING gist (geometry_point); + +CREATE SCHEMA IF NOT EXISTS boundary_polygon; + +CREATE TABLE IF NOT EXISTS boundary_polygon.updates +( + id serial PRIMARY KEY, + t text, + UNIQUE (t) +); + +CREATE OR REPLACE FUNCTION boundary_polygon.flag() RETURNS trigger AS +$$ +BEGIN + INSERT INTO boundary_polygon.updates(t) VALUES ('y') ON CONFLICT(t) DO NOTHING; + RETURN NULL; +END; +$$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION boundary_polygon.refresh() RETURNS trigger AS +$$ +DECLARE + t TIMESTAMP WITH TIME ZONE := clock_timestamp(); +BEGIN + RAISE LOG 'Refresh boundary_polygon'; + + -- Analyze tracking and source tables before performing update + ANALYZE osm_boundary_polygon_gen_z5; + REFRESH MATERIALIZED VIEW osm_boundary_polygon_gen_z5; + + -- noinspection SqlWithoutWhere + DELETE FROM boundary_polygon.updates; + + RAISE LOG 'Refresh boundary_polygon done in %', age(clock_timestamp(), t); + RETURN NULL; +END; +$$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION update_osm_boundary_polygon_row() + RETURNS trigger +AS +$$ +BEGIN + NEW.tags = update_tags(NEW.tags, NEW.geometry); + NEW.geometry_point = st_centroid(NEW.geometry); + RETURN NEW; +END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER update_row + BEFORE INSERT OR UPDATE + ON osm_boundary_polygon + FOR EACH ROW +EXECUTE PROCEDURE update_osm_boundary_polygon_row(); + +CREATE TRIGGER update_row + BEFORE INSERT OR UPDATE + ON osm_boundary_polygon_gen_z13 + FOR EACH ROW +EXECUTE PROCEDURE update_osm_boundary_polygon_row(); + +CREATE TRIGGER update_row + BEFORE INSERT OR UPDATE + ON osm_boundary_polygon_gen_z12 + FOR EACH ROW +EXECUTE PROCEDURE update_osm_boundary_polygon_row(); + +CREATE TRIGGER update_row + BEFORE INSERT OR UPDATE + ON osm_boundary_polygon_gen_z11 + FOR EACH ROW +EXECUTE PROCEDURE update_osm_boundary_polygon_row(); + +CREATE TRIGGER update_row + BEFORE INSERT OR UPDATE + ON osm_boundary_polygon_gen_z10 + FOR EACH ROW +EXECUTE PROCEDURE update_osm_boundary_polygon_row(); + +CREATE TRIGGER update_row + BEFORE INSERT OR UPDATE + ON osm_boundary_polygon_gen_z9 + FOR EACH ROW +EXECUTE PROCEDURE update_osm_boundary_polygon_row(); + +CREATE TRIGGER update_row + BEFORE INSERT OR UPDATE + ON osm_boundary_polygon_gen_z8 + FOR EACH ROW +EXECUTE PROCEDURE update_osm_boundary_polygon_row(); + +CREATE TRIGGER update_row + BEFORE INSERT OR UPDATE + ON osm_boundary_polygon_gen_z7 + FOR EACH ROW +EXECUTE PROCEDURE update_osm_boundary_polygon_row(); + +CREATE TRIGGER update_row + BEFORE INSERT OR UPDATE + ON osm_boundary_polygon_gen_z6 + FOR EACH ROW +EXECUTE PROCEDURE update_osm_boundary_polygon_row(); + +CREATE TRIGGER update_row + BEFORE INSERT OR UPDATE + ON osm_boundary_polygon_gen_z5 + FOR EACH ROW +EXECUTE PROCEDURE update_osm_boundary_polygon_row(); + +CREATE TRIGGER trigger_flag + AFTER INSERT OR UPDATE OR DELETE + ON osm_boundary_polygon + FOR EACH STATEMENT +EXECUTE PROCEDURE boundary_polygon.flag(); + +CREATE CONSTRAINT TRIGGER trigger_refresh + AFTER INSERT + ON boundary_polygon.updates + INITIALLY DEFERRED + FOR EACH ROW +EXECUTE PROCEDURE boundary_polygon.refresh(); diff --git a/layers/park/mapping.yaml b/layers/park/mapping.yaml index 4a955693..746803c2 100644 --- a/layers/park/mapping.yaml +++ b/layers/park/mapping.yaml @@ -101,4 +101,3 @@ tables: boundary: - national_park - protected_area - - aboriginal_lands diff --git a/layers/park/mapping_diagram.png b/layers/park/mapping_diagram.png index 45c2c197..72d2edb8 100644 Binary files a/layers/park/mapping_diagram.png and b/layers/park/mapping_diagram.png differ diff --git a/layers/park/park.sql b/layers/park/park.sql index bf2f07de..4b90696e 100644 --- a/layers/park/park.sql +++ b/layers/park/park.sql @@ -26,12 +26,11 @@ SELECT osm_id, FROM ( SELECT osm_id, geometry, - CASE WHEN boundary='aboriginal_lands' THEN 'aboriginal_lands' - ELSE COALESCE( - LOWER(REPLACE(NULLIF(protection_title, ''), ' ', '_')), - NULLIF(boundary, ''), - NULLIF(leisure, '') - ) END AS class, + COALESCE( + LOWER(REPLACE(NULLIF(protection_title, ''), ' ', '_')), + NULLIF(boundary, ''), + NULLIF(leisure, '')) + AS class, name, name_en, name_de, @@ -46,7 +45,7 @@ FROM ( NULL AS name_de, NULL AS tags, NULL AS leisure, - CASE WHEN boundary='aboriginal_lands' THEN boundary END AS boundary, + NULL AS boundary, NULL AS protection_title FROM osm_park_polygon_dissolve_z4 WHERE zoom_level = 4 diff --git a/layers/park/park.yaml b/layers/park/park.yaml index 1ae0543a..000155d0 100644 --- a/layers/park/park.yaml +++ b/layers/park/park.yaml @@ -5,15 +5,11 @@ layer: such as parks tagged with [`boundary=national_park`](https://wiki.openstreetmap.org/wiki/Tag:boundary%3Dnational_park), [`boundary=protected_area`](https://wiki.openstreetmap.org/wiki/Tag:boundary%3Dprotected_area), or [`leisure=nature_reserve`](https://wiki.openstreetmap.org/wiki/Tag:leisure%3Dnature_reserve). - This layer also includes boundaries for indigenous lands tagged with - [`boundary=aboriginal_lands`](https://wiki.openstreetmap.org/wiki/Tag:boundary%3Daboriginal_lands). - Indigenous boundaries are not parks, but they are included in this layer for technical reasons related to data processing. - These boundaries represent areas with special legal and administrative status for indigenous peoples. buffer_size: 4 fields: class: description: | - Use the **class** to differentiate between different kinds of features in the `parks` layer, for example between parks and non-parks. + Use the **class** to differentiate between different kinds of features in the `parks` layer. The class for `boundary=protected_area` parks is the lower-case of the [`protection_title`](http://wiki.openstreetmap.org/wiki/key:protection_title) value with blanks replaced by `_`. @@ -21,7 +17,6 @@ layer: `nature_reserve` is the class of `protection_title=Nature Reserve` and `leisure=nature_reserve`. The class for other [`protection_title`](http://wiki.openstreetmap.org/wiki/key:protection_title) values is similarly assigned. - The class for `boundary=aboriginal_lands` is `aboriginal_lands`. name: The OSM [`name`](http://wiki.openstreetmap.org/wiki/Key:name) value of the park (point features only). Language-specific values are in `name:xx`. name_en: English name `name:en` if available, otherwise `name` (point features only). This is deprecated and will be removed in a future release in favor of `name:en`. name_de: German name `name:de` if available, otherwise `name` or `name:en` (point features only). This is deprecated and will be removed in a future release in favor of `name:de`. diff --git a/layers/place/island_rank.sql b/layers/place/area_rank.sql similarity index 69% rename from layers/place/island_rank.sql rename to layers/place/area_rank.sql index f7ef3efa..7ef3c7af 100644 --- a/layers/place/island_rank.sql +++ b/layers/place/area_rank.sql @@ -1,10 +1,12 @@ -CREATE OR REPLACE FUNCTION island_rank(area real) RETURNS int AS +CREATE OR REPLACE FUNCTION area_rank(area real) RETURNS int AS $$ SELECT CASE WHEN area < 10000000 THEN 6 WHEN area BETWEEN 1000000 AND 15000000 THEN 5 WHEN area BETWEEN 15000000 AND 40000000 THEN 4 WHEN area > 40000000 THEN 3 + WHEN area > 160000000 THEN 2 + WHEN area > 640000000 THEN 1 ELSE 7 END; $$ LANGUAGE SQL IMMUTABLE diff --git a/layers/place/etl_diagram.png b/layers/place/etl_diagram.png index de2cb08b..b5a0a53f 100644 Binary files a/layers/place/etl_diagram.png and b/layers/place/etl_diagram.png differ diff --git a/layers/place/place.sql b/layers/place/place.sql index c232124c..7c6fa0ed 100644 --- a/layers/place/place.sql +++ b/layers/place/place.sql @@ -109,17 +109,39 @@ FROM ( COALESCE(NULLIF(name_de, ''), name, name_en) AS name_de, tags, 'island' AS class, - island_rank(area) AS "rank", + area_rank(area) AS "rank", NULL::int AS capital, NULL::text AS iso_a2 FROM osm_island_polygon WHERE geometry && bbox - AND ((zoom_level = 8 AND island_rank(area) <= 3) - OR (zoom_level = 9 AND island_rank(area) <= 4) + AND ((zoom_level = 8 AND area_rank(area) <= 3) + OR (zoom_level = 9 AND area_rank(area) <= 4) OR (zoom_level >= 10)) UNION ALL + SELECT + -- etldoc: osm_boundary_polygon -> layer_place:z6_11 + -- etldoc: osm_boundary_polygon -> layer_place:z12_14 + osm_id * 10 AS osm_id, + geometry_point, + name, + NULL::text AS name_en, -- deprecated + NULL::text AS name_de, -- deprecated + tags, + 'aboriginal_lands' AS class, + area_rank(area) AS "rank", + NULL::int AS capital, + NULL::text AS iso_a2 + FROM osm_boundary_polygon + WHERE geometry_point && bbox + AND ((zoom_level = 6 AND area_rank(area) <= 1) + OR (zoom_level = 7 AND area_rank(area) <= 2) + OR (zoom_level = 8 AND area_rank(area) <= 3) + OR (zoom_level = 9 AND area_rank(area) <= 4) + OR (zoom_level >= 10)) + UNION ALL + SELECT -- etldoc: layer_city -> layer_place:z0_3 -- etldoc: layer_city -> layer_place:z4_7 diff --git a/layers/place/place.yaml b/layers/place/place.yaml index e4d5a57c..6f46332c 100644 --- a/layers/place/place.yaml +++ b/layers/place/place.yaml @@ -5,6 +5,9 @@ layer: - ne_10m_admin_1_states_provinces - ne_10m_admin_0_countries - ne_10m_populated_places + requires: + layers: + - boundary description: | The place layer consists out of [countries](http://wiki.openstreetmap.org/wiki/Tag:place%3Dcountry), [states](http://wiki.openstreetmap.org/wiki/Tag:place%3Dstate), [cities](http://wiki.openstreetmap.org/wiki/Key:place) @@ -28,7 +31,9 @@ layer: Distinguish between continents, countries, states, islands and places like settlements or smaller entities. Use **class** to separately style the different places and build - a text hierarchy according to their importance. + a text hierarchy according to their importance. For places derived + from boundaries, the original value of the + [`boundary`](http://wiki.openstreetmap.org/wiki/Key:boundary) tag. values: - continent - country @@ -44,6 +49,7 @@ layer: - neighbourhood - isolated_dwelling - island + - aboriginal_lands iso_a2: description: | Two-letter country code [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2). Available only for `class=country`. @@ -75,7 +81,7 @@ schema: - ./types.sql - ./capital.sql - ./city.sql - - ./island_rank.sql + - ./area_rank.sql - ./update_continent_point.sql - ./update_country_point.sql - ./update_island_polygon.sql diff --git a/layers/transportation/update_transportation_merge.sql b/layers/transportation/update_transportation_merge.sql index 74b3c7b8..d6876658 100644 --- a/layers/transportation/update_transportation_merge.sql +++ b/layers/transportation/update_transportation_merge.sql @@ -144,6 +144,8 @@ CREATE TABLE IF NOT EXISTS osm_transportation_merge_linestring_gen_z11( layer integer ); +ALTER TABLE osm_transportation_merge_linestring_gen_z11 ADD COLUMN IF NOT EXISTS source_ids bigint[]; + -- Create osm_transportation_merge_linestring_gen_z10 as a copy of osm_transportation_merge_linestring_gen_z11 but -- drop the "source_ids" column. This can be done because z10 and z9 tables are only simplified and not merged, -- therefore relations to sources are direct via the id column. @@ -459,6 +461,8 @@ CREATE TABLE IF NOT EXISTS osm_transportation_merge_linestring_gen_z8( z_order integer ); +ALTER TABLE osm_transportation_merge_linestring_gen_z8 ADD COLUMN IF NOT EXISTS source_ids bigint[]; + -- Create osm_transportation_merge_linestring_gen_z7 as a copy of osm_transportation_merge_linestring_gen_z8 but -- drop the "source_ids" column. This can be done because z7 to z5 tables are only simplified and not merged, -- therefore relations to sources are direct via the id column. diff --git a/layers/transportation_name/update_transportation_name.sql b/layers/transportation_name/update_transportation_name.sql index a6043b31..6a4be4c6 100644 --- a/layers/transportation_name/update_transportation_name.sql +++ b/layers/transportation_name/update_transportation_name.sql @@ -61,6 +61,8 @@ CREATE TABLE IF NOT EXISTS osm_transportation_name_linestring( route_rank integer ); +ALTER TABLE osm_transportation_name_linestring ADD COLUMN IF NOT EXISTS source_ids bigint[]; + -- Create OneToMany-Relation-Table storing relations of a Merged-LineString in table -- osm_transportation_name_linestring to Source-LineStrings from tables osm_transportation_name_network, -- osm_shipway_linestring and osm_aerialway_linestring diff --git a/layers/waterway/update_important_waterway.sql b/layers/waterway/update_important_waterway.sql index 134fdaf7..aa0105ea 100644 --- a/layers/waterway/update_important_waterway.sql +++ b/layers/waterway/update_important_waterway.sql @@ -27,6 +27,8 @@ CREATE TABLE IF NOT EXISTS osm_important_waterway_linestring ( tags hstore ); +ALTER TABLE osm_important_waterway_linestring ADD COLUMN IF NOT EXISTS source_ids bigint[]; + -- Create osm_important_waterway_linestring_gen_z11 as a copy of osm_important_waterway_linestring but drop the -- "source_ids" column. This can be done because z10 and z9 tables are only simplified and not merged, therefore -- relations to sources are direct via the id column.