Move place to imposm3 mapping

This commit is contained in:
lukasmartinelli 2016-10-10 20:19:18 +02:00
parent a48123657c
commit 8bc57e13e7
3 changed files with 52 additions and 23 deletions

33
layers/place/mapping.yaml Normal file
View File

@ -0,0 +1,33 @@
tables:
place_point:
type: geometry
fields:
- name: osm_id
type: id
- name: geometry
type: geometry
- key: name
name: name
type: string
- name: name_en
key: name:en
type: string
- name: place
key: place
type: string
- key: population
name: population
type: integer
filters:
exclude_tags:
- [ "name", "__nil__" ]
type_mappings:
points:
place:
- city
- town
- village
- hamlet
- suburb
- neighbourhood
- isolated_dwelling

View File

@ -1,70 +1,63 @@
CREATE OR REPLACE VIEW place_z2 AS ( CREATE OR REPLACE VIEW place_z2 AS (
SELECT geom, name, 'settlement' AS class, 'city'::place AS rank, scalerank, pop_min AS population SELECT geom, name, 'city' AS place, scalerank, pop_min AS population
FROM ne_10m_populated_places FROM ne_10m_populated_places
WHERE scalerank <= 0 WHERE scalerank <= 0
); );
CREATE OR REPLACE VIEW place_z3 AS ( CREATE OR REPLACE VIEW place_z3 AS (
SELECT geom, name, 'settlement' AS class, 'city'::place AS rank, scalerank, pop_min AS population SELECT geom, name, 'city' AS place, scalerank, pop_min AS population
FROM ne_10m_populated_places FROM ne_10m_populated_places
WHERE scalerank <= 2 WHERE scalerank <= 2
); );
CREATE OR REPLACE VIEW place_z4 AS ( CREATE OR REPLACE VIEW place_z4 AS (
SELECT geom, name, 'settlement' AS class, 'city'::place AS rank, scalerank, pop_min AS population SELECT geom, name, 'city' AS place, scalerank, pop_min AS population
FROM ne_10m_populated_places FROM ne_10m_populated_places
WHERE scalerank <= 5 WHERE scalerank <= 5
); );
CREATE OR REPLACE VIEW place_z5 AS ( CREATE OR REPLACE VIEW place_z5 AS (
SELECT geom, name, 'settlement' AS class, 'city'::place AS rank, scalerank, pop_min AS population SELECT geom, name, 'city' AS place, scalerank, pop_min AS population
FROM ne_10m_populated_places FROM ne_10m_populated_places
WHERE scalerank <= 6 WHERE scalerank <= 6
); );
CREATE OR REPLACE VIEW place_z6 AS ( CREATE OR REPLACE VIEW place_z6 AS (
SELECT geom, name, 'settlement' AS class, 'city'::place AS rank, scalerank, pop_min AS population SELECT geom, name, 'city' AS place, scalerank, pop_min AS population
FROM ne_10m_populated_places FROM ne_10m_populated_places
WHERE scalerank <= 7 WHERE scalerank <= 7
); );
CREATE OR REPLACE VIEW place_z7 AS ( CREATE OR REPLACE VIEW place_z7 AS (
SELECT geom, name, 'settlement' AS class, 'city'::place AS rank, scalerank, pop_min AS population SELECT geom, name, 'city' AS place, scalerank, pop_min AS population
FROM ne_10m_populated_places FROM ne_10m_populated_places
); );
CREATE OR REPLACE VIEW place_z8 AS ( CREATE OR REPLACE VIEW place_z8 AS (
SELECT way AS geom, name, class::text, rank, NULL::integer AS scalerank, population FROM place_point SELECT geometry AS geom, name, place, NULL::integer AS scalerank, population FROM osm_place_point
WHERE rank IN ('city', 'town') WHERE place IN ('city', 'town')
); );
CREATE OR REPLACE VIEW place_z10 AS ( CREATE OR REPLACE VIEW place_z10 AS (
SELECT way AS geom, name, class::text, rank, NULL::integer AS scalerank, population FROM place_point SELECT geometry AS geom, name, place, NULL::integer AS scalerank, population FROM osm_place_point
WHERE rank IN ('city', 'town', 'village') OR class='subregion' WHERE place IN ('city', 'town', 'village') OR place='subregion'
); );
CREATE OR REPLACE VIEW place_z11 AS ( CREATE OR REPLACE VIEW place_z11 AS (
SELECT way AS geom, name, class::text, rank, NULL::integer AS scalerank, population FROM place_point SELECT geometry AS geom, name, place, NULL::integer AS scalerank, population FROM osm_place_point
WHERE class IN ('subregion', 'settlement')
); );
CREATE OR REPLACE VIEW place_z13 AS ( CREATE OR REPLACE VIEW place_z13 AS (
SELECT way AS geom, name, class::text, rank, NULL::integer AS scalerank, population FROM place_point SELECT geometry AS geom, name, place, NULL::integer AS scalerank, population FROM osm_place_point
); );
CREATE OR REPLACE FUNCTION layer_place(bbox geometry, zoom_level int, pixel_width numeric) CREATE OR REPLACE FUNCTION layer_place(bbox geometry, zoom_level int, pixel_width numeric)
RETURNS TABLE(geom geometry, name text, class text, rank text, scalerank int) AS $$ RETURNS TABLE(geom geometry, name text, place text, scalerank int) AS $$
SELECT geom, name, class, rank::text, scalerank FROM ( SELECT geom, name, place, scalerank FROM (
SELECT geom, name, class, rank, scalerank, SELECT geom, name, place, scalerank,
row_number() OVER ( row_number() OVER (
PARTITION BY LabelGrid(geom, 150 * pixel_width) PARTITION BY LabelGrid(geom, 150 * pixel_width)
ORDER BY scalerank ASC NULLS LAST, ORDER BY scalerank ASC NULLS LAST,
CASE class
WHEN 'settlement' THEN 10
WHEN 'subregion' THEN 5
WHEN 'locality' THEN 2 ELSE 1
END DESC,
rank DESC,
population DESC NULLS LAST, population DESC NULLS LAST,
length(name) DESC length(name) DESC
) AS gridrank ) AS gridrank

View File

@ -1,8 +1,11 @@
layer: layer:
id: "place" id: "place"
description: place description: [OSM Places](http://wiki.openstreetmap.org/wiki/Key:place)
buffer_size: 128 buffer_size: 128
datasource: datasource:
query: (SELECT * FROM layer_place(!bbox!, z(!scale_denominator!), !pixel_width!)) AS t query: (SELECT * FROM layer_place(!bbox!, z(!scale_denominator!), !pixel_width!)) AS t
schema: schema:
- ./place.sql - ./place.sql
datasources:
- type: imposm3
mapping_file: ./mapping.yaml