diff --git a/layers/transportation/etl_diagram.png b/layers/transportation/etl_diagram.png index 479b9edb..6cb789c9 100644 Binary files a/layers/transportation/etl_diagram.png and b/layers/transportation/etl_diagram.png differ diff --git a/layers/transportation/mapping.yaml b/layers/transportation/mapping.yaml index 34984a03..f5109c30 100644 --- a/layers/transportation/mapping.yaml +++ b/layers/transportation/mapping.yaml @@ -367,6 +367,33 @@ tables: - bridge - pier + # etldoc: imposm3 -> highway_point + highway_point: + type: point + columns: + - name: osm_id + type: id + - name: geometry + type: geometry + - name: highway + key: highway + type: string + - name: z_order + type: wayzorder + - *layer + - *level + - *name + - *name_en + - *name_de + - name: tags + type: hstore_tags + - name: ref + key: ref + type: string + mapping: + highway: + - motorway_junction + # TODO: Future table for joining networks # etldoc: imposm3 -> osm_route_member route_member: diff --git a/layers/transportation/mapping_diagram.png b/layers/transportation/mapping_diagram.png index 959e43b4..6dc9a777 100644 Binary files a/layers/transportation/mapping_diagram.png and b/layers/transportation/mapping_diagram.png differ diff --git a/layers/transportation_name/etl_diagram.png b/layers/transportation_name/etl_diagram.png index dacb8c16..4e60abb8 100644 Binary files a/layers/transportation_name/etl_diagram.png and b/layers/transportation_name/etl_diagram.png differ diff --git a/layers/transportation_name/highway_classification.sql b/layers/transportation_name/highway_classification.sql new file mode 100644 index 00000000..b9f8e07e --- /dev/null +++ b/layers/transportation_name/highway_classification.sql @@ -0,0 +1,57 @@ +CREATE OR REPLACE FUNCTION highway_to_val(hwy_class varchar) +RETURNS int +IMMUTABLE +LANGUAGE plpgsql +AS $$ +BEGIN + CASE hwy_class + WHEN 'motorway' THEN RETURN 6; + WHEN 'trunk' THEN RETURN 5; + WHEN 'primary' THEN RETURN 4; + WHEN 'secondary' THEN RETURN 3; + WHEN 'tertiary' THEN RETURN 2; + WHEN 'unclassified' THEN RETURN 1; + else RETURN 0; + END CASE; +END; +$$; + +CREATE OR REPLACE FUNCTION val_to_highway(hwy_val int) +RETURNS varchar +IMMUTABLE +LANGUAGE plpgsql +AS $$ +BEGIN + CASE hwy_val + WHEN 6 THEN RETURN 'motorway'; + WHEN 5 THEN RETURN 'trunk'; + WHEN 4 THEN RETURN 'primary'; + WHEN 3 THEN RETURN 'secondary'; + WHEN 2 THEN RETURN 'tertiary'; + WHEN 1 THEN RETURN 'unclassified'; + else RETURN null; + END CASE; +END; +$$; + +CREATE OR REPLACE FUNCTION highest_hwy_sfunc(agg_state varchar, hwy_class varchar) +RETURNS varchar +IMMUTABLE +LANGUAGE plpgsql +AS $$ +BEGIN + RETURN val_to_highway( + GREATEST( + highway_to_val(agg_state), + highway_to_val(hwy_class) + ) + ); +END; +$$; + +DROP AGGREGATE IF EXISTS highest_highway (varchar); +CREATE AGGREGATE highest_highway (varchar) +( + sfunc = highest_hwy_sfunc, + stype = varchar +); diff --git a/layers/transportation_name/mapping_diagram.png b/layers/transportation_name/mapping_diagram.png index 959e43b4..6dc9a777 100644 Binary files a/layers/transportation_name/mapping_diagram.png and b/layers/transportation_name/mapping_diagram.png differ diff --git a/layers/transportation_name/transportation_name.sql b/layers/transportation_name/transportation_name.sql index 9a282814..452488d8 100644 --- a/layers/transportation_name/transportation_name.sql +++ b/layers/transportation_name/transportation_name.sql @@ -37,10 +37,11 @@ SELECT osm_id, WHEN length(coalesce(ref, '')) > 0 THEN 'road' END AS network, - highway_class(highway, '', construction) AS class, + highway_class(highway, '', subclass) AS class, CASE - WHEN highway IS NOT NULL AND highway_class(highway, '', construction) = 'path' + WHEN highway IS NOT NULL AND highway_class(highway, '', subclass) = 'path' THEN highway + ELSE subclass END AS subclass, brunnel, NULLIF(layer, 0) AS layer, @@ -95,7 +96,7 @@ FROM ( "tags", ref, highway, - construction, + subclass, brunnel, network, z_order, @@ -105,7 +106,7 @@ FROM ( FROM osm_transportation_name_linestring WHERE zoom_level = 12 AND LineLabel(zoom_level, COALESCE(name, ref), geometry) - AND highway_class(highway, '', construction) NOT IN ('minor', 'track', 'path') + AND highway_class(highway, '', subclass) NOT IN ('minor', 'track', 'path') AND NOT highway_is_link(highway) UNION ALL @@ -118,7 +119,7 @@ FROM ( "tags", ref, highway, - construction, + subclass, brunnel, network, z_order, @@ -128,7 +129,7 @@ FROM ( FROM osm_transportation_name_linestring WHERE zoom_level = 13 AND LineLabel(zoom_level, COALESCE(name, ref), geometry) - AND highway_class(highway, '', construction) NOT IN ('track', 'path') + AND highway_class(highway, '', subclass) NOT IN ('track', 'path') UNION ALL -- etldoc: osm_transportation_name_linestring -> layer_transportation_name:z14_ @@ -140,7 +141,7 @@ FROM ( "tags", ref, highway, - construction, + subclass, brunnel, network, z_order, @@ -149,6 +150,32 @@ FROM ( indoor FROM osm_transportation_name_linestring WHERE zoom_level >= 14 + UNION ALL + + -- etldoc: osm_highway_point -> layer_transportation_name:z10 + SELECT + p.geometry, + p.osm_id, + p.name, + p.name_en, + p.name_de, + p.tags, + p.tags->'ref', + ( + SELECT highest_highway(l.tags->'highway') + FROM osm_highway_linestring l + WHERE ST_Intersects(p.geometry,l.geometry) + ) AS class, + 'junction'::text AS subclass, + NULL AS brunnel, + NULL AS network, + z_order, + layer, + NULL::int AS level, + NULL::boolean AS indoor + FROM osm_highway_point p + WHERE highway = 'motorway_junction' AND zoom_level >= 10 + ) AS zoom_levels WHERE geometry && bbox ORDER BY z_order ASC; diff --git a/layers/transportation_name/transportation_name.yaml b/layers/transportation_name/transportation_name.yaml index 331929e9..a6c60864 100644 --- a/layers/transportation_name/transportation_name.yaml +++ b/layers/transportation_name/transportation_name.yaml @@ -55,11 +55,13 @@ layer: - raceway_construction - rail - transit + - motorway_junction subclass: description: | Distinguish more specific classes of path: Subclass is value of the - [`highway`](http://wiki.openstreetmap.org/wiki/Key:highway) (for paths). + [`highway`](http://wiki.openstreetmap.org/wiki/Key:highway) (for paths), + and "junction" for [`motorway junctions`](http://wiki.openstreetmap.org/wiki/Tag:highway=motorway_junction). values: - pedestrian - path @@ -69,6 +71,7 @@ layer: - bridleway - corridor - platform + - junction brunnel: description: | Mark whether way is a bridge, a tunnel or a ford. @@ -96,6 +99,7 @@ layer: query: (SELECT geometry, name, name_en, name_de, {name_languages}, ref, ref_length, network::text, class::text, subclass, brunnel, layer, level, indoor FROM layer_transportation_name(!bbox!, z(!scale_denominator!))) AS t schema: - ./network_type.sql + - ./highway_classification.sql - ./update_route_member.sql - ./update_transportation_name.sql - ./transportation_name.sql diff --git a/layers/transportation_name/update_transportation_name.sql b/layers/transportation_name/update_transportation_name.sql index d50cc56a..d6fbb44a 100644 --- a/layers/transportation_name/update_transportation_name.sql +++ b/layers/transportation_name/update_transportation_name.sql @@ -16,7 +16,7 @@ SELECT tags, ref, highway, - construction, + subclass, brunnel, "level", layer, @@ -37,7 +37,7 @@ FROM ( ELSE NULLIF(hl.ref, '') END AS ref, hl.highway, - hl.construction, + hl.construction AS subclass, brunnel(hl.is_bridge, hl.is_tunnel, hl.is_ford) AS brunnel, CASE WHEN highway IN ('footway', 'steps') THEN layer END AS layer, CASE WHEN highway IN ('footway', 'steps') THEN level END AS level, @@ -67,7 +67,7 @@ SELECT (ST_Dump(geometry)).geom AS geometry, tags || get_basic_names(tags, geometry) AS "tags", ref, highway, - construction, + subclass, brunnel, "level", layer, @@ -83,7 +83,7 @@ FROM ( ARRAY ['name', name, 'name:en', name_en, 'name:de', name_de]) AS tags, ref, highway, - construction, + subclass, brunnel, "level", layer, @@ -91,14 +91,14 @@ FROM ( network_type, min(z_order) AS z_order FROM osm_transportation_name_network - GROUP BY name, name_en, name_de, tags, ref, highway, construction, brunnel, "level", layer, indoor, network_type + GROUP BY name, name_en, name_de, tags, ref, highway, subclass, brunnel, "level", layer, indoor, network_type ) AS highway_union ; CREATE INDEX IF NOT EXISTS osm_transportation_name_linestring_name_ref_idx ON osm_transportation_name_linestring (coalesce(name, ''), coalesce(ref, '')); CREATE INDEX IF NOT EXISTS osm_transportation_name_linestring_geometry_idx ON osm_transportation_name_linestring USING gist (geometry); CREATE INDEX IF NOT EXISTS osm_transportation_name_linestring_highway_partial_idx - ON osm_transportation_name_linestring (highway, construction) + ON osm_transportation_name_linestring (highway, subclass) WHERE highway IN ('motorway', 'trunk', 'construction'); -- etldoc: osm_transportation_name_linestring -> osm_transportation_name_linestring_gen1 @@ -111,12 +111,12 @@ SELECT ST_Simplify(geometry, 50) AS geometry, tags, ref, highway, - construction, + subclass, brunnel, network, z_order FROM osm_transportation_name_linestring -WHERE (highway IN ('motorway', 'trunk') OR highway = 'construction' AND construction IN ('motorway', 'trunk')) +WHERE (highway IN ('motorway', 'trunk') OR highway = 'construction' AND subclass IN ('motorway', 'trunk')) AND ST_Length(geometry) > 8000 ; CREATE TABLE IF NOT EXISTS osm_transportation_name_linestring_gen1 AS @@ -126,7 +126,7 @@ CREATE INDEX IF NOT EXISTS osm_transportation_name_linestring_gen1_name_ref_idx CREATE INDEX IF NOT EXISTS osm_transportation_name_linestring_gen1_geometry_idx ON osm_transportation_name_linestring_gen1 USING gist (geometry); CREATE INDEX IF NOT EXISTS osm_transportation_name_linestring_gen1_highway_partial_idx - ON osm_transportation_name_linestring_gen1 (highway, construction) + ON osm_transportation_name_linestring_gen1 (highway, subclass) WHERE highway IN ('motorway', 'trunk', 'construction'); -- etldoc: osm_transportation_name_linestring_gen1 -> osm_transportation_name_linestring_gen2 @@ -139,12 +139,12 @@ SELECT ST_Simplify(geometry, 120) AS geometry, tags, ref, highway, - construction, + subclass, brunnel, network, z_order FROM osm_transportation_name_linestring_gen1 -WHERE (highway IN ('motorway', 'trunk') OR highway = 'construction' AND construction IN ('motorway', 'trunk')) +WHERE (highway IN ('motorway', 'trunk') OR highway = 'construction' AND subclass IN ('motorway', 'trunk')) AND ST_Length(geometry) > 14000 ; CREATE TABLE IF NOT EXISTS osm_transportation_name_linestring_gen2 AS @@ -154,7 +154,7 @@ CREATE INDEX IF NOT EXISTS osm_transportation_name_linestring_gen2_name_ref_idx CREATE INDEX IF NOT EXISTS osm_transportation_name_linestring_gen2_geometry_idx ON osm_transportation_name_linestring_gen2 USING gist (geometry); CREATE INDEX IF NOT EXISTS osm_transportation_name_linestring_gen2_highway_partial_idx - ON osm_transportation_name_linestring_gen2 (highway, construction) + ON osm_transportation_name_linestring_gen2 (highway, subclass) WHERE highway IN ('motorway', 'trunk', 'construction'); -- etldoc: osm_transportation_name_linestring_gen2 -> osm_transportation_name_linestring_gen3 @@ -167,12 +167,12 @@ SELECT ST_Simplify(geometry, 200) AS geometry, tags, ref, highway, - construction, + subclass, brunnel, network, z_order FROM osm_transportation_name_linestring_gen2 -WHERE (highway = 'motorway' OR highway = 'construction' AND construction = 'motorway') +WHERE (highway = 'motorway' OR highway = 'construction' AND subclass = 'motorway') AND ST_Length(geometry) > 20000 ; CREATE TABLE IF NOT EXISTS osm_transportation_name_linestring_gen3 AS @@ -182,7 +182,7 @@ CREATE INDEX IF NOT EXISTS osm_transportation_name_linestring_gen3_name_ref_idx CREATE INDEX IF NOT EXISTS osm_transportation_name_linestring_gen3_geometry_idx ON osm_transportation_name_linestring_gen3 USING gist (geometry); CREATE INDEX IF NOT EXISTS osm_transportation_name_linestring_gen3_highway_partial_idx - ON osm_transportation_name_linestring_gen3 (highway, construction) + ON osm_transportation_name_linestring_gen3 (highway, subclass) WHERE highway IN ('motorway', 'construction'); -- etldoc: osm_transportation_name_linestring_gen3 -> osm_transportation_name_linestring_gen4 @@ -195,12 +195,12 @@ SELECT ST_Simplify(geometry, 500) AS geometry, tags, ref, highway, - construction, + subclass, brunnel, network, z_order FROM osm_transportation_name_linestring_gen3 -WHERE (highway = 'motorway' OR highway = 'construction' AND construction = 'motorway') +WHERE (highway = 'motorway' OR highway = 'construction' AND subclass = 'motorway') AND ST_Length(geometry) > 20000 ; CREATE TABLE IF NOT EXISTS osm_transportation_name_linestring_gen4 AS @@ -282,7 +282,7 @@ BEGIN tags, ref, highway, - construction, + subclass, brunnel, level, layer, @@ -303,7 +303,7 @@ BEGIN ELSE NULLIF(hl.ref, '') END AS ref, hl.highway, - hl.construction, + hl.subclass, brunnel(hl.is_bridge, hl.is_tunnel, hl.is_ford) AS brunnel, CASE WHEN highway IN ('footway', 'steps') THEN layer END AS layer, CASE WHEN highway IN ('footway', 'steps') THEN level END AS level, @@ -369,7 +369,7 @@ CREATE TABLE IF NOT EXISTS transportation_name.name_changes name_de character varying, ref character varying, highway character varying, - construction character varying, + subclass character varying, brunnel character varying, level integer, layer integer, @@ -382,16 +382,16 @@ $$ BEGIN IF (tg_op IN ('DELETE', 'UPDATE')) THEN - INSERT INTO transportation_name.name_changes(is_old, osm_id, name, name_en, name_de, ref, highway, construction, + INSERT INTO transportation_name.name_changes(is_old, osm_id, name, name_en, name_de, ref, highway, subclass, brunnel, level, layer, indoor, network_type) - VALUES (TRUE, old.osm_id, old.name, old.name_en, old.name_de, old.ref, old.highway, old.construction, + VALUES (TRUE, old.osm_id, old.name, old.name_en, old.name_de, old.ref, old.highway, old.subclass, old.brunnel, old.level, old.layer, old.indoor, old.network_type); END IF; IF (tg_op IN ('UPDATE', 'INSERT')) THEN - INSERT INTO transportation_name.name_changes(is_old, osm_id, name, name_en, name_de, ref, highway, construction, + INSERT INTO transportation_name.name_changes(is_old, osm_id, name, name_en, name_de, ref, highway, subclass, brunnel, level, layer, indoor, network_type) - VALUES (FALSE, new.osm_id, new.name, new.name_en, new.name_de, new.ref, new.highway, new.construction, + VALUES (FALSE, new.osm_id, new.name, new.name_en, new.name_de, new.ref, new.highway, new.subclass, new.brunnel, new.level, new.layer, new.indoor, new.network_type); END IF; RETURN NULL; @@ -423,13 +423,13 @@ BEGIN -- Compact the change history to keep only the first and last version, and then uniq version of row CREATE TEMP TABLE name_changes_compact AS - SELECT DISTINCT ON (name, name_en, name_de, ref, highway, construction, brunnel, level, layer, indoor, network_type) + SELECT DISTINCT ON (name, name_en, name_de, ref, highway, subclass, brunnel, level, layer, indoor, network_type) name, name_en, name_de, ref, highway, - construction, + subclass, brunnel, level, layer, @@ -460,7 +460,7 @@ BEGIN AND n.name_en IS NOT DISTINCT FROM c.name_en AND n.name_de IS NOT DISTINCT FROM c.name_de AND n.highway IS NOT DISTINCT FROM c.highway - AND n.construction IS NOT DISTINCT FROM c.construction + AND n.subclass IS NOT DISTINCT FROM c.subclass AND n.brunnel IS NOT DISTINCT FROM c.brunnel AND n.level IS NOT DISTINCT FROM c.level AND n.layer IS NOT DISTINCT FROM c.layer @@ -476,7 +476,7 @@ BEGIN tags || get_basic_names(tags, geometry) AS tags, ref, highway, - construction, + subclass, brunnel, level, layer, @@ -493,7 +493,7 @@ BEGIN ''), ',')) AS tags, n.ref, n.highway, - n.construction, + n.subclass, n.brunnel, n.level, n.layer, @@ -507,13 +507,13 @@ BEGIN AND n.name_en IS NOT DISTINCT FROM c.name_en AND n.name_de IS NOT DISTINCT FROM c.name_de AND n.highway IS NOT DISTINCT FROM c.highway - AND n.construction IS NOT DISTINCT FROM c.construction + AND n.subclass IS NOT DISTINCT FROM c.subclass AND n.brunnel IS NOT DISTINCT FROM c.brunnel AND n.level IS NOT DISTINCT FROM c.level AND n.layer IS NOT DISTINCT FROM c.layer AND n.indoor IS NOT DISTINCT FROM c.indoor AND n.network_type IS NOT DISTINCT FROM c.network_type - GROUP BY n.name, n.name_en, n.name_de, n.ref, n.highway, n.construction, n.brunnel, n.level, n.layer, n.indoor, n.network_type + GROUP BY n.name, n.name_en, n.name_de, n.ref, n.highway, n.subclass, n.brunnel, n.level, n.layer, n.indoor, n.network_type ) AS highway_union; -- REFRESH osm_transportation_name_linestring_gen1 @@ -526,7 +526,7 @@ BEGIN AND n.name_de IS NOT DISTINCT FROM c.name_de AND n.ref IS NOT DISTINCT FROM c.ref AND n.highway IS NOT DISTINCT FROM c.highway - AND n.construction IS NOT DISTINCT FROM c.construction + AND n.subclass IS NOT DISTINCT FROM c.subclass AND n.brunnel IS NOT DISTINCT FROM c.brunnel AND n.network IS NOT DISTINCT FROM c.network_type; @@ -540,7 +540,7 @@ BEGIN AND n.name_de IS NOT DISTINCT FROM c.name_de AND n.ref IS NOT DISTINCT FROM c.ref AND n.highway IS NOT DISTINCT FROM c.highway - AND n.construction IS NOT DISTINCT FROM c.construction + AND n.subclass IS NOT DISTINCT FROM c.subclass AND n.brunnel IS NOT DISTINCT FROM c.brunnel AND n.network IS NOT DISTINCT FROM c.network_type; @@ -554,7 +554,7 @@ BEGIN AND n.name_de IS NOT DISTINCT FROM c.name_de AND n.ref IS NOT DISTINCT FROM c.ref AND n.highway IS NOT DISTINCT FROM c.highway - AND n.construction IS NOT DISTINCT FROM c.construction + AND n.subclass IS NOT DISTINCT FROM c.subclass AND n.brunnel IS NOT DISTINCT FROM c.brunnel AND n.network IS NOT DISTINCT FROM c.network_type; @@ -568,7 +568,7 @@ BEGIN AND n.name_de IS NOT DISTINCT FROM c.name_de AND n.ref IS NOT DISTINCT FROM c.ref AND n.highway IS NOT DISTINCT FROM c.highway - AND n.construction IS NOT DISTINCT FROM c.construction + AND n.subclass IS NOT DISTINCT FROM c.subclass AND n.brunnel IS NOT DISTINCT FROM c.brunnel AND n.network IS NOT DISTINCT FROM c.network_type; @@ -582,7 +582,7 @@ BEGIN AND n.name_de IS NOT DISTINCT FROM c.name_de AND n.ref IS NOT DISTINCT FROM c.ref AND n.highway IS NOT DISTINCT FROM c.highway - AND n.construction IS NOT DISTINCT FROM c.construction + AND n.subclass IS NOT DISTINCT FROM c.subclass AND n.brunnel IS NOT DISTINCT FROM c.brunnel AND n.network IS NOT DISTINCT FROM c.network_type; @@ -596,7 +596,7 @@ BEGIN AND n.name_de IS NOT DISTINCT FROM c.name_de AND n.ref IS NOT DISTINCT FROM c.ref AND n.highway IS NOT DISTINCT FROM c.highway - AND n.construction IS NOT DISTINCT FROM c.construction + AND n.subclass IS NOT DISTINCT FROM c.subclass AND n.brunnel IS NOT DISTINCT FROM c.brunnel AND n.network IS NOT DISTINCT FROM c.network_type; @@ -610,7 +610,7 @@ BEGIN AND n.name_de IS NOT DISTINCT FROM c.name_de AND n.ref IS NOT DISTINCT FROM c.ref AND n.highway IS NOT DISTINCT FROM c.highway - AND n.construction IS NOT DISTINCT FROM c.construction + AND n.subclass IS NOT DISTINCT FROM c.subclass AND n.brunnel IS NOT DISTINCT FROM c.brunnel AND n.network IS NOT DISTINCT FROM c.network_type; @@ -624,7 +624,7 @@ BEGIN AND n.name_de IS NOT DISTINCT FROM c.name_de AND n.ref IS NOT DISTINCT FROM c.ref AND n.highway IS NOT DISTINCT FROM c.highway - AND n.construction IS NOT DISTINCT FROM c.construction + AND n.subclass IS NOT DISTINCT FROM c.subclass AND n.brunnel IS NOT DISTINCT FROM c.brunnel AND n.network IS NOT DISTINCT FROM c.network_type;