Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add length of trails to transportation layer #5

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 30 additions & 21 deletions layers/transportation/layer.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand 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
Expand 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
Expand 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
Expand 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
Expand 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)
Expand All @@ -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)
Expand All @@ -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 (
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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 = ''
Expand All @@ -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 = ''
Expand All @@ -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 = ''
Expand All @@ -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 = ''
Expand All @@ -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
Expand 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
Expand 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
Expand 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
Expand 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
Expand 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
Expand Down
5 changes: 4 additions & 1 deletion layers/transportation/transportation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down