diff --git a/layers/transportation/layer.sql b/layers/transportation/layer.sql index 2fd2d5cbf..fd626242b 100644 --- a/layers/transportation/layer.sql +++ b/layers/transportation/layer.sql @@ -8,7 +8,8 @@ $$ LANGUAGE SQL IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION layer_transportation(bbox geometry, zoom_level int) RETURNS TABLE(osm_id bigint, geometry geometry, class text, subclass text, ramp int, oneway int, brunnel TEXT, service TEXT, layer INT, level INT, -indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) AS $$ +indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT, +trail_length INT) AS $$ SELECT osm_id, geometry, CASE @@ -38,7 +39,8 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A NULLIF(foot, '') AS foot, NULLIF(horse, '') AS horse, NULLIF(mtb_scale, '') AS mtb_scale, - NULLIF(surface, '') AS surface + NULLIF(surface, '') AS surface, + NULLIF(trail_length, -1) AS trail_length FROM ( -- etldoc: osm_transportation_merge_linestring_gen7 -> layer_transportation:z4 SELECT @@ -50,7 +52,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL as man_made, NULL::int AS layer, NULL::int AS level, NULL::boolean AS indoor, NULL as bicycle, NULL as foot, NULL as horse, NULL as mtb_scale, - NULL AS surface, z_order + NULL AS surface, NULL::int AS trail_length, z_order FROM osm_transportation_merge_linestring_gen7 WHERE zoom_level = 4 UNION ALL @@ -65,7 +67,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL as man_made, NULL::int AS layer, NULL::int AS level, NULL::boolean AS indoor, NULL as bicycle, NULL as foot, NULL as horse, NULL as mtb_scale, - NULL AS surface, z_order + NULL AS surface, NULL::int AS trail_length, z_order FROM osm_transportation_merge_linestring_gen6 WHERE zoom_level = 5 UNION ALL @@ -80,7 +82,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL as man_made, NULL::int AS layer, NULL::int AS level, NULL::boolean AS indoor, NULL as bicycle, NULL as foot, NULL as horse, NULL as mtb_scale, - NULL AS surface, z_order + NULL AS surface, NULL::int AS trail_length, z_order FROM osm_transportation_merge_linestring_gen5 WHERE zoom_level = 6 UNION ALL @@ -95,7 +97,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL as man_made, NULL::int AS layer, NULL::int AS level, NULL::boolean AS indoor, NULL as bicycle, NULL as foot, NULL as horse, NULL as mtb_scale, - NULL AS surface, z_order + NULL AS surface, NULL::int AS trail_length, z_order FROM osm_transportation_merge_linestring_gen4 WHERE zoom_level = 7 UNION ALL @@ -110,7 +112,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL as man_made, NULL::int AS layer, NULL::int AS level, NULL::boolean AS indoor, NULL as bicycle, NULL as foot, NULL as horse, NULL as mtb_scale, - NULL AS surface, z_order + NULL AS surface, NULL::int AS trail_length, z_order FROM osm_transportation_merge_linestring_gen3 WHERE zoom_level = 8 UNION ALL @@ -126,7 +128,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL as man_made, layer, NULL::int AS level, NULL::boolean AS indoor, bicycle, foot, horse, mtb_scale, - NULL AS surface, z_order + NULL AS surface, NULL::int AS trail_length, z_order FROM osm_highway_linestring_gen2 WHERE zoom_level BETWEEN 9 AND 10 AND st_length(geometry)>zres(11) @@ -142,7 +144,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL as man_made, layer, NULL::int AS level, NULL::boolean AS indoor, bicycle, foot, horse, mtb_scale, - NULL AS surface, z_order + NULL AS surface, NULL::int AS trail_length, z_order FROM osm_highway_linestring_gen1 WHERE zoom_level = 11 AND st_length(geometry)>zres(12) @@ -165,6 +167,13 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A END AS indoor, bicycle, foot, horse, mtb_scale, surface_value(surface) AS "surface", + -- NOTE: You can't just do geometry::geography because the current srid is 900913 + -- (pseudo mercator). It needs to be in lat/lon, so I first convert to WGS84, then cast + -- to geography. + CASE WHEN highway IN ('pedestrian', 'path', 'footway', 'cycleway', 'steps', 'bridleway', 'corridor') + THEN round(ST_Length(ST_Transform(geometry, 4326)::geography))::int + ELSE NULL::int + END AS "trail_length", z_order FROM osm_highway_linestring WHERE NOT is_area AND ( @@ -199,7 +208,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL as man_made, NULL::int AS layer, NULL::int AS level, NULL::boolean AS indoor, NULL as bicycle, NULL as foot, NULL as horse, NULL as mtb_scale, - NULL as surface, z_order + NULL as surface, NULL::int AS trail_length, z_order FROM osm_railway_linestring_gen5 WHERE zoom_level = 8 AND railway='rail' AND service = '' and usage='main' @@ -215,7 +224,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A NULL::boolean AS is_ramp, NULL::int AS is_oneway, NULL as man_made, layer, NULL::int AS level, NULL::boolean AS indoor, NULL as bicycle, NULL as foot, NULL as horse, NULL as mtb_scale, - NULL AS surface, z_order + NULL AS surface, NULL::int AS trail_length, z_order FROM osm_railway_linestring_gen4 WHERE zoom_level = 9 AND railway='rail' AND service = '' and usage='main' @@ -229,7 +238,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, NULL as man_made, layer, NULL::int AS level, NULL::boolean AS indoor, NULL as bicycle, NULL as foot, NULL as horse, NULL as mtb_scale, - NULL AS surface, z_order + NULL AS surface, NULL::int AS trail_length, z_order FROM osm_railway_linestring_gen3 WHERE zoom_level = 10 AND railway IN ('rail', 'narrow_gauge') AND service = '' @@ -243,7 +252,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, NULL as man_made, layer, NULL::int AS level, NULL::boolean AS indoor, NULL as bicycle, NULL as foot, NULL as horse, NULL as mtb_scale, - NULL as surface, z_order + NULL as surface, NULL::int AS trail_length, z_order FROM osm_railway_linestring_gen2 WHERE zoom_level = 11 AND railway IN ('rail', 'narrow_gauge', 'light_rail') AND service = '' @@ -257,7 +266,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, NULL as man_made, layer, NULL::int AS level, NULL::boolean AS indoor, NULL as bicycle, NULL as foot, NULL as horse, NULL as mtb_scale, - NULL as surface, z_order + NULL as surface, NULL::int AS trail_length, z_order FROM osm_railway_linestring_gen1 WHERE zoom_level = 12 AND railway IN ('rail', 'narrow_gauge', 'light_rail') AND service = '' @@ -272,7 +281,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, NULL as man_made, layer, NULL::int AS level, NULL::boolean AS indoor, NULL as bicycle, NULL as foot, NULL as horse, NULL as mtb_scale, - NULL as surface, z_order + NULL as surface, NULL::int AS trail_length, z_order FROM osm_railway_linestring WHERE zoom_level = 13 AND railway IN ('rail', 'narrow_gauge', 'light_rail') AND service = '' @@ -287,7 +296,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, NULL as man_made, layer, NULL::int AS level, NULL::boolean AS indoor, NULL as bicycle, NULL as foot, NULL as horse, NULL as mtb_scale, - NULL AS surface, z_order + NULL AS surface, NULL::int AS trail_length, z_order FROM osm_aerialway_linestring_gen1 WHERE zoom_level = 12 UNION ALL @@ -301,7 +310,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, NULL as man_made, layer, NULL::int AS level, NULL::boolean AS indoor, NULL as bicycle, NULL as foot, NULL as horse, NULL as mtb_scale, - NULL AS surface, z_order + NULL AS surface, NULL::int AS trail_length, z_order FROM osm_aerialway_linestring WHERE zoom_level >= 13 UNION ALL @@ -314,7 +323,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, NULL as man_made, layer, NULL::int AS level, NULL::boolean AS indoor, NULL as bicycle, NULL as foot, NULL as horse, NULL as mtb_scale, - NULL AS surface, z_order + NULL AS surface, NULL::int AS trail_length, z_order FROM osm_shipway_linestring_gen2 WHERE zoom_level = 11 UNION ALL @@ -327,7 +336,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, NULL as man_made, layer, NULL::int AS level, NULL::boolean AS indoor, NULL as bicycle, NULL as foot, NULL as horse, NULL as mtb_scale, - NULL AS surface, z_order + NULL AS surface, NULL::int AS trail_length, z_order FROM osm_shipway_linestring_gen1 WHERE zoom_level = 12 UNION ALL @@ -341,7 +350,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, NULL as man_made, layer, NULL::int AS level, NULL::boolean AS indoor, NULL as bicycle, NULL as foot, NULL as horse, NULL as mtb_scale, - NULL AS surface, z_order + NULL AS surface, NULL::int AS trail_length, z_order FROM osm_shipway_linestring WHERE zoom_level >= 13 UNION ALL @@ -362,7 +371,7 @@ indoor INT, bicycle TEXT, foot TEXT, horse TEXT, mtb_scale TEXT, surface TEXT) A FALSE AS is_ramp, FALSE::int AS is_oneway, man_made, layer, NULL::int AS level, NULL::boolean AS indoor, NULL as bicycle, NULL as foot, NULL as horse, NULL as mtb_scale, - NULL AS surface, z_order + NULL AS surface, NULL::int AS trail_length, z_order FROM osm_highway_polygon -- We do not want underground pedestrian areas for now WHERE zoom_level >= 13 diff --git a/layers/transportation/transportation.yaml b/layers/transportation/transportation.yaml index b92f6504b..b94fbb2ca 100644 --- a/layers/transportation/transportation.yaml +++ b/layers/transportation/transportation.yaml @@ -135,10 +135,13 @@ layer: values: - paved - unpaved + trail_length: + description: | + Distance in meters of trail linestring. Only defined for class=path. datasource: geometry_field: geometry srid: 900913 - query: (SELECT geometry, class, subclass, oneway, ramp, brunnel, service, layer, level, indoor, bicycle, foot, horse, mtb_scale, surface FROM layer_transportation(!bbox!, z(!scale_denominator!))) AS t + query: (SELECT geometry, class, subclass, oneway, ramp, brunnel, service, layer, level, indoor, bicycle, foot, horse, mtb_scale, surface, trail_length FROM layer_transportation(!bbox!, z(!scale_denominator!))) AS t schema: - ./class.sql - ./update_transportation_merge.sql