diff --git a/layers/transportation/layer.sql b/layers/transportation/layer.sql index cd8b8bd..4314395 100644 --- a/layers/transportation/layer.sql +++ b/layers/transportation/layer.sql @@ -6,10 +6,14 @@ $$ LANGUAGE SQL IMMUTABLE STRICT; -- etldoc: layer_transportation[shape=record fillcolor=lightpink, style="rounded,filled", -- etldoc: label=" layer_transportation | z4-z7 | z8 | z9 | z10 | z11 | z12| z13| z14_" ] ; CREATE OR REPLACE FUNCTION layer_transportation(bbox geometry, zoom_level int) -RETURNS TABLE(osm_id bigint, geometry geometry, class highway_class, subclass text, ramp int, oneway int, brunnel TEXT) AS $$ +RETURNS TABLE(osm_id bigint, geometry geometry, class text, subclass text, ramp int, oneway int, brunnel TEXT) AS $$ SELECT osm_id, geometry, - to_highway_class(highway) AS class, highway AS subclass, + CASE + WHEN highway <> '' THEN to_highway_class(highway) + WHEN railway <> '' THEN railway_class(railway, service) + END AS class, + COALESCE(NULLIF(highway,''), NULLIF(railway, '')) AS subclass, CASE WHEN highway_is_link(highway) THEN 1 ELSE is_ramp::int END AS ramp, is_oneway::int AS oneway, to_brunnel(is_bridge, is_tunnel, is_ford) AS brunnel @@ -17,7 +21,7 @@ RETURNS TABLE(osm_id bigint, geometry geometry, class highway_class, subclass te -- etldoc: ne_10m_global_roads -> layer_transportation:z4z6 SELECT - NULL::bigint AS osm_id, geometry, highway, + NULL::bigint AS osm_id, geometry, highway, NULL AS railway, NULL AS service, FALSE AS is_bridge, FALSE AS is_tunnel, FALSE AS is_ford, FALSE AS is_ramp, FALSE AS is_oneway, 0 AS z_order FROM ne_10m_global_roads @@ -25,48 +29,48 @@ RETURNS TABLE(osm_id bigint, geometry geometry, class highway_class, subclass te UNION ALL -- etldoc: osm_transportation_linestring_gen4 -> layer_transportation:z7z8 - SELECT osm_id, geometry, highway, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order + SELECT osm_id, geometry, highway, railway, NULL AS service, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order FROM osm_transportation_linestring_gen4 WHERE zoom_level BETWEEN 7 AND 8 UNION ALL -- etldoc: osm_transportation_linestring_gen3 -> layer_transportation:z9 - SELECT osm_id, geometry, highway, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order + SELECT osm_id, geometry, highway, railway, NULL AS service, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order FROM osm_transportation_linestring_gen3 WHERE zoom_level = 9 UNION ALL -- etldoc: osm_transportation_linestring_gen2 -> layer_transportation:z10 - SELECT osm_id, geometry, highway, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order + SELECT osm_id, geometry, highway, railway, NULL AS service, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order FROM osm_transportation_linestring_gen2 WHERE zoom_level = 10 UNION ALL -- etldoc: osm_transportation_linestring_gen1 -> layer_transportation:z11 - SELECT osm_id, geometry, highway, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order + SELECT osm_id, geometry, highway, railway, NULL AS service, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order FROM osm_transportation_linestring_gen1 WHERE zoom_level = 11 UNION ALL -- etldoc: osm_transportation_linestring -> layer_transportation:z12 - SELECT osm_id, geometry, highway, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order + SELECT osm_id, geometry, highway, railway, NULL AS service, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order FROM osm_transportation_linestring WHERE zoom_level = 12 - AND (to_highway_class(highway) < 'minor_road'::highway_class OR highway IN ('unclassified', 'residential')) + AND (to_highway_class(highway) NOT IN ('minor_road', 'path') OR highway IN ('unclassified', 'residential')) AND NOT highway_is_link(highway) AND NOT is_area UNION ALL -- etldoc: osm_transportation_linestring -> layer_transportation:z13 - SELECT osm_id, geometry, highway, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order + SELECT osm_id, geometry, highway, railway, NULL AS service, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order FROM osm_transportation_linestring WHERE zoom_level = 13 - AND to_highway_class(highway) < 'path'::highway_class + AND to_highway_class(highway) <> 'path' AND NOT is_area UNION ALL -- etldoc: osm_transportation_linestring -> layer_transportation:z14_ - SELECT osm_id, geometry, highway, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order + SELECT osm_id, geometry, highway, railway, NULL AS service, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order FROM osm_transportation_linestring WHERE zoom_level >= 14 AND NOT is_area UNION ALL @@ -75,7 +79,7 @@ RETURNS TABLE(osm_id bigint, geometry geometry, class highway_class, subclass te -- it is possible that closed linestrings appear both as highway linestrings and as polygon -- etldoc: osm_transportation__polygon -> layer_transportation:z13 -- etldoc: osm_transportation__polygon -> layer_transportation:z14_ - SELECT osm_id, geometry, highway, FALSE AS is_bridge, FALSE AS is_tunnel, FALSE AS is_ford, FALSE AS is_ramp, FALSE AS is_oneway, z_order + SELECT osm_id, geometry, highway, NULL AS railway, NULL AS service, FALSE AS is_bridge, FALSE AS is_tunnel, FALSE AS is_ford, FALSE AS is_ramp, FALSE AS is_oneway, z_order FROM osm_transportation_polygon -- We do not want underground pedestrian areas for now WHERE zoom_level >= 13 AND is_area AND COALESCE(layer, 0) >= 0 diff --git a/layers/transportation/transportation.yaml b/layers/transportation/transportation.yaml index 05d96e2..a309d87 100644 --- a/layers/transportation/transportation.yaml +++ b/layers/transportation/transportation.yaml @@ -29,7 +29,7 @@ layer: datasource: geometry_field: geometry srid: 900913 - query: (SELECT geometry, class::text, subclass, oneway, ramp, brunnel FROM layer_transportation(!bbox!, z(!scale_denominator!))) AS t + query: (SELECT geometry, class, subclass, oneway, ramp, brunnel FROM layer_transportation(!bbox!, z(!scale_denominator!))) AS t schema: - ./types.sql - ./ne_global_roads.sql diff --git a/layers/transportation/types.sql b/layers/transportation/types.sql index e9560bc..fc1d75b 100644 --- a/layers/transportation/types.sql +++ b/layers/transportation/types.sql @@ -1,13 +1,3 @@ - - -DO $$ -BEGIN - IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'highway_class') THEN - CREATE TYPE highway_class AS ENUM ('motorway', 'major_road', 'minor_road', 'path'); - END IF; -END -$$; - CREATE OR REPLACE FUNCTION to_brunnel(is_bridge BOOL, is_tunnel BOOL, is_ford BOOL) RETURNS TEXT AS $$ SELECT CASE WHEN is_bridge THEN 'bridge' @@ -17,16 +7,23 @@ CREATE OR REPLACE FUNCTION to_brunnel(is_bridge BOOL, is_tunnel BOOL, is_ford BO END; $$ LANGUAGE SQL IMMUTABLE STRICT; -CREATE OR REPLACE FUNCTION to_highway_class(highway TEXT) RETURNS highway_class AS $$ +CREATE OR REPLACE FUNCTION to_highway_class(highway TEXT) RETURNS TEXT AS $$ SELECT CASE - WHEN highway IN ('motorway', 'motorway_link') THEN 'motorway'::highway_class + WHEN highway IN ('motorway', 'motorway_link') THEN 'motorway' -- A major class is helpful in styling - one can still differentiate on a finer level using the subclass WHEN highway IN ('trunk', 'trunk_link', 'primary', 'primary_link', 'secondary', 'secondary_link', - 'tertiary', 'tertiary_link') THEN 'major_road'::highway_class - WHEN highway IN ('unclassified', 'residential', 'living_street', 'road', 'track', 'service') THEN 'minor_road'::highway_class - WHEN highway IN ('pedestrian', 'path', 'footway', 'cycleway', 'steps') THEN 'path'::highway_class + 'tertiary', 'tertiary_link') THEN 'major_road' + WHEN highway IN ('unclassified', 'residential', 'living_street', 'road', 'track', 'service') THEN 'minor_road' + WHEN highway IN ('pedestrian', 'path', 'footway', 'cycleway', 'steps') THEN 'path' ELSE NULL END; $$ LANGUAGE SQL IMMUTABLE STRICT; + +CREATE OR REPLACE FUNCTION railway_class(railway text, service text) RETURNS TEXT AS $$ + SELECT CASE + WHEN railway='rail' AND service='' THEN 'rail' + ELSE 'minor_rail' + END; +$$ LANGUAGE SQL IMMUTABLE; diff --git a/layers/transportation_name/layer.sql b/layers/transportation_name/layer.sql index 6f62a9c..0e435bc 100644 --- a/layers/transportation_name/layer.sql +++ b/layers/transportation_name/layer.sql @@ -3,7 +3,7 @@ -- etldoc: label="layer_transportation_name | z8 | z9 | z10 | z11 | z12| z13| z14_" ] ; CREATE OR REPLACE FUNCTION layer_transportation_name(bbox geometry, zoom_level integer) -RETURNS TABLE(osm_id bigint, geometry geometry, name text, ref text, ref_length int, class highway_class, subclass text) AS $$ +RETURNS TABLE(osm_id bigint, geometry geometry, name text, ref text, ref_length int, class text, subclass text) AS $$ SELECT osm_id, geometry, name, NULLIF(ref, ''), NULLIF(LENGTH(ref), 0) AS ref_length, to_highway_class(highway) AS class, highway AS subclass @@ -29,7 +29,7 @@ RETURNS TABLE(osm_id bigint, geometry geometry, name text, ref text, ref_length SELECT * FROM osm_transportation_name_linestring WHERE zoom_level = 12 AND LineLabel(zoom_level, COALESCE(NULLIF(name, ''), ref), geometry) - AND to_highway_class(highway) < 'minor_road'::highway_class + AND to_highway_class(highway) NOT IN ('minor_road', 'path') AND NOT highway_is_link(highway) UNION ALL @@ -37,7 +37,7 @@ RETURNS TABLE(osm_id bigint, geometry geometry, name text, ref text, ref_length SELECT * FROM osm_transportation_name_linestring WHERE zoom_level = 13 AND LineLabel(zoom_level, COALESCE(NULLIF(name, ''), ref), geometry) - AND to_highway_class(highway) < 'path'::highway_class + AND to_highway_class(highway) <> 'path' UNION ALL -- etldoc: osm_transportation_name_linestring -> layer_transportation_name:z14_