kopia lustrzana https://github.com/openmaptiles/openmaptiles
Add agg_stop indicator to transit stations (POI)
rodzic
1c2ce970fd
commit
543b0315b2
|
@ -3,7 +3,7 @@
|
|||
-- etldoc: label="layer_poi | <z12> z12 | <z13> z13 | <z14_> z14+" ] ;
|
||||
|
||||
CREATE OR REPLACE FUNCTION layer_poi(bbox geometry, zoom_level integer, pixel_width numeric)
|
||||
RETURNS TABLE(osm_id bigint, geometry geometry, name text, name_en text, name_de text, tags hstore, class text, subclass text, "rank" int) AS $$
|
||||
RETURNS TABLE(osm_id bigint, geometry geometry, name text, name_en text, name_de text, tags hstore, class text, subclass text, agg_stop integer, "rank" int) AS $$
|
||||
SELECT osm_id, geometry, NULLIF(name, '') AS name,
|
||||
COALESCE(NULLIF(name_en, ''), name) AS name_en,
|
||||
COALESCE(NULLIF(name_de, ''), name, name_en) AS name_de,
|
||||
|
@ -14,6 +14,7 @@ RETURNS TABLE(osm_id bigint, geometry geometry, name text, name_en text, name_de
|
|||
THEN NULLIF(information, '')
|
||||
ELSE subclass
|
||||
END AS subclass,
|
||||
agg_stop,
|
||||
row_number() OVER (
|
||||
PARTITION BY LabelGrid(geometry, 100 * pixel_width)
|
||||
ORDER BY CASE WHEN name = '' THEN 2000 ELSE poi_class_rank(poi_class(subclass, mapping_key)) END ASC
|
||||
|
@ -35,14 +36,18 @@ RETURNS TABLE(osm_id bigint, geometry geometry, name text, name_en text, name_de
|
|||
UNION ALL
|
||||
-- etldoc: osm_poi_polygon -> layer_poi:z12
|
||||
-- etldoc: osm_poi_polygon -> layer_poi:z13
|
||||
SELECT * FROM osm_poi_polygon
|
||||
SELECT *,
|
||||
NULL::INTEGER AS agg_stop
|
||||
FROM osm_poi_polygon
|
||||
WHERE geometry && bbox
|
||||
AND zoom_level BETWEEN 12 AND 13
|
||||
AND ((subclass='station' AND mapping_key = 'railway')
|
||||
OR subclass IN ('halt', 'ferry_terminal'))
|
||||
UNION ALL
|
||||
-- etldoc: osm_poi_polygon -> layer_poi:z14_
|
||||
SELECT * FROM osm_poi_polygon
|
||||
SELECT *,
|
||||
NULL::INTEGER AS agg_stop
|
||||
FROM osm_poi_polygon
|
||||
WHERE geometry && bbox
|
||||
AND zoom_level >= 14
|
||||
) as poi_union
|
||||
|
|
|
@ -333,6 +333,9 @@ tables:
|
|||
- name: information
|
||||
key: information
|
||||
type: string
|
||||
- name: uic_ref
|
||||
key: uic_ref
|
||||
type: string
|
||||
mapping:
|
||||
aerialway: *poi_mapping_aerialway
|
||||
amenity: *poi_mapping_amenity
|
||||
|
@ -380,6 +383,9 @@ tables:
|
|||
- name: information
|
||||
key: information
|
||||
type: string
|
||||
- name: uic_ref
|
||||
key: uic_ref
|
||||
type: string
|
||||
mapping:
|
||||
aerialway: *poi_mapping_aerialway
|
||||
amenity: *poi_mapping_amenity
|
||||
|
|
|
@ -32,14 +32,24 @@ layer:
|
|||
local relative importance of a POI within it's cell in the grid. This can be used to reduce label density at *z14*.
|
||||
Since all POIs already need to be contained at *z14* you can use `less than rank=10` epxression to limit
|
||||
POIs. At some point like *z17* you can show all POIs.
|
||||
agg_stop:
|
||||
description: |
|
||||
Experimental feature! Indicates main platform of public transport
|
||||
stops (buses, trams, and subways). Grouping of platforms is
|
||||
implemented using
|
||||
[`uic_ref`](http://wiki.openstreetmap.org/wiki/Key:uic_ref) tag that
|
||||
is not used worldwide.
|
||||
values: [1]
|
||||
datasource:
|
||||
geometry_field: geometry
|
||||
srid: 900913
|
||||
query: (SELECT geometry, name, name_en, name_de, {name_languages}, class, subclass, rank FROM layer_poi(!bbox!, z(!scale_denominator!), !pixel_width!)) AS t
|
||||
query: (SELECT geometry, name, name_en, name_de, {name_languages}, class, subclass, agg_stop, rank FROM layer_poi(!bbox!, z(!scale_denominator!), !pixel_width!)) AS t
|
||||
schema:
|
||||
- ./public_transport_stop_type.sql
|
||||
- ./update_poi_polygon.sql
|
||||
- ./update_poi_point.sql
|
||||
- ./class.sql
|
||||
- ./poi_stop_agg.sql
|
||||
- ./layer.sql
|
||||
datasources:
|
||||
- type: imposm3
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
DROP MATERIALIZED VIEW IF EXISTS osm_poi_stop_centroid CASCADE;
|
||||
CREATE MATERIALIZED VIEW osm_poi_stop_centroid AS (
|
||||
SELECT
|
||||
uic_ref,
|
||||
count(*) as count,
|
||||
CASE WHEN count(*) > 2 THEN ST_Centroid(ST_UNION(geometry))
|
||||
ELSE NULL END AS centroid
|
||||
FROM osm_poi_point
|
||||
WHERE
|
||||
nullif(uic_ref, '') IS NOT NULL
|
||||
AND subclass IN ('bus_stop', 'bus_station', 'tram_stop', 'subway')
|
||||
GROUP BY
|
||||
uic_ref
|
||||
HAVING
|
||||
count(*) > 1
|
||||
);
|
||||
|
||||
DROP MATERIALIZED VIEW IF EXISTS osm_poi_stop_rank CASCADE;
|
||||
CREATE MATERIALIZED VIEW osm_poi_stop_rank AS (
|
||||
SELECT
|
||||
p.osm_id,
|
||||
-- p.uic_ref,
|
||||
-- p.subclass,
|
||||
ROW_NUMBER()
|
||||
OVER (
|
||||
PARTITION BY p.uic_ref
|
||||
ORDER BY
|
||||
p.subclass :: public_transport_stop_type NULLS LAST,
|
||||
ST_Distance(c.centroid, p.geometry)
|
||||
) AS rk
|
||||
FROM osm_poi_point p
|
||||
INNER JOIN osm_poi_stop_centroid c ON (p.uic_ref = c.uic_ref)
|
||||
WHERE
|
||||
subclass IN ('bus_stop', 'bus_station', 'tram_stop', 'subway')
|
||||
ORDER BY p.uic_ref, rk
|
||||
);
|
||||
|
||||
ALTER TABLE osm_poi_point ADD COLUMN IF NOT EXISTS agg_stop INTEGER DEFAULT NULL;
|
||||
SELECT update_osm_poi_point_agg();
|
|
@ -0,0 +1,11 @@
|
|||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT 1
|
||||
FROM pg_type
|
||||
WHERE typname = 'public_transport_stop_type') THEN
|
||||
CREATE TYPE public_transport_stop_type AS ENUM (
|
||||
'subway', 'tram_stop', 'bus_station', 'bus_stop'
|
||||
);
|
||||
END IF;
|
||||
END
|
||||
$$;
|
|
@ -21,6 +21,30 @@ $$ LANGUAGE plpgsql;
|
|||
|
||||
SELECT update_osm_poi_point();
|
||||
|
||||
CREATE OR REPLACE FUNCTION update_osm_poi_point_agg() RETURNS VOID AS $$
|
||||
BEGIN
|
||||
UPDATE osm_poi_point p
|
||||
SET agg_stop = CASE
|
||||
WHEN p.subclass IN ('bus_stop', 'bus_station', 'tram_stop', 'subway')
|
||||
THEN 1
|
||||
ELSE NULL
|
||||
END;
|
||||
|
||||
UPDATE osm_poi_point p
|
||||
SET agg_stop = (
|
||||
CASE
|
||||
WHEN p.subclass IN ('bus_stop', 'bus_station', 'tram_stop', 'subway')
|
||||
AND r.rk IS NULL OR r.rk = 1
|
||||
THEN 1
|
||||
ELSE NULL
|
||||
END)
|
||||
FROM osm_poi_stop_rank r
|
||||
WHERE p.osm_id = r.osm_id
|
||||
;
|
||||
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
-- Handle updates
|
||||
|
||||
CREATE SCHEMA IF NOT EXISTS poi_point;
|
||||
|
@ -38,6 +62,9 @@ CREATE OR REPLACE FUNCTION poi_point.refresh() RETURNS trigger AS
|
|||
BEGIN
|
||||
RAISE LOG 'Refresh poi_point';
|
||||
PERFORM update_osm_poi_point();
|
||||
REFRESH MATERIALIZED VIEW osm_poi_stop_centroid;
|
||||
REFRESH MATERIALIZED VIEW osm_poi_stop_rank;
|
||||
PERFORM update_osm_poi_point_agg();
|
||||
DELETE FROM poi_point.updates;
|
||||
RETURN null;
|
||||
END;
|
||||
|
|
Ładowanie…
Reference in New Issue