Skip to content

Commit

Permalink
5033 roads bridges tunnels queries (#5035)
Browse files Browse the repository at this point in the history
* Do not calculate surface for railways.

* Name the value for access in railway branch.

* Do not calculate service for railways.

* link is always null for railways.

* preserved is always null for roads.

* All other CASE statements are not parenthesized.

* Alignment.

* Documentation.

* Documentation.

* Copy roads_sql subqueries to tunnels.

* Copy roads_sql subqueries to bridges.

* Spurious spaces.

* Duped SELECT.

* changing column name from access to int_access

---------

Co-authored-by: imagico <git@imagico.de>
  • Loading branch information
StyXman and imagico authored Nov 27, 2024
1 parent 6164c07 commit 5791e79
Showing 1 changed file with 51 additions and 33 deletions.
84 changes: 51 additions & 33 deletions project.mml
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,14 @@ Layer:
<<: *extents
Datasource:
<<: *osm2pgsql
# This query is quite large, having to deal with both roads, railways. To
# allow for ways that are both railways and roads, a UNION ALL is present.
# NOTE: There are 3 similar queries: here and in the roads-casing and bridges layers. Any change introduced
# in this query must be considered for inclusion in the other two. Changes in the WHERE clause should be
# particularly thought through.

# This is one of the most complex layers, so it bears explaining in some detail
# It is necessary to
# - Have roads and railways in the same layer to get ordering right
# - Return two linestrings for ways which are both a road and railway
table: |-
(SELECT
way,
Expand All @@ -459,21 +465,22 @@ Layer:
tracktype,
CASE WHEN surface IN ('unpaved', 'compacted', 'dirt', 'earth', 'fine_gravel', 'grass', 'grass_paver', 'gravel', 'ground',
'mud', 'pebblestone', 'salt', 'sand', 'woodchips', 'clay', 'ice', 'snow') THEN 'unpaved'
WHEN surface IN ('paved', 'asphalt', 'cobblestone', 'cobblestone:flattened', 'sett', 'concrete', 'concrete:lanes',
WHEN surface IN ('paved', 'asphalt', 'cobblestone', 'cobblestone:flattened', 'sett', 'concrete', 'concrete:lanes',
'concrete:plates', 'paving_stones', 'metal', 'wood', 'unhewn_cobblestone') THEN 'paved'
END AS int_surface,
carto_highway_int_access(highway, access, foot, bicycle, horse, tags->'motorcar', tags->'motor_vehicle', tags->'vehicle') AS int_access,
construction,
CASE
WHEN service IN ('parking_aisle', 'drive-through', 'driveway') THEN 'INT-minor'::text
WHEN service IN ('parking_aisle', 'drive-through', 'driveway') OR leisure IN ('slipway') THEN 'INT-minor'::text
ELSE 'INT-normal'::text
END AS service,
CASE
WHEN highway IN ('motorway_link', 'trunk_link', 'primary_link', 'secondary_link', 'tertiary_link') THEN 'yes'
ELSE 'no'
END AS link,
'no' as preserved,
NULL AS preserved,
COALESCE(layer,0) AS layernotnull,
osm_id,
z_order
FROM planet_osm_line
WHERE (tunnel = 'yes' OR tunnel = 'building_passage' OR covered = 'yes')
Expand All @@ -486,16 +493,17 @@ Layer:
WHEN (railway = 'tram' AND service IN ('spur', 'siding', 'yard')) THEN 'tram-service'
ELSE railway END) AS feature,
tracktype,
'null',
NULL,
NULL AS int_surface,
NULL AS int_access,
construction,
CASE WHEN service IN ('parking_aisle', 'drive-through', 'driveway') THEN 'INT-minor'::text ELSE 'INT-normal'::text END AS service,
'no' AS link,
(CASE
NULL AS service,
NULL AS link,
CASE
WHEN tags->'railway:preserved' = 'yes' THEN 'yes'
ELSE 'no'
END) AS preserved,
END AS preserved,
COALESCE(layer,0) AS layernotnull,
osm_id,
z_order
FROM planet_osm_line
WHERE (tunnel = 'yes' OR tunnel = 'building_passage' OR covered = 'yes')
Expand Down Expand Up @@ -665,6 +673,10 @@ Layer:
<<: *extents
Datasource:
<<: *osm2pgsql
# NOTE: There are 3 similar queries: here and in the tunnels and bridges layers. Any change introduced
# in this query must be considered for inclusion in the other two. Changes in the WHERE clause should be
# particularly thought through.

# This is one of the most complex layers, so it bears explaining in some detail
# It is necessary to
# - Have roads and railways in the same layer to get ordering right
Expand All @@ -688,7 +700,7 @@ Layer:
tracktype,
CASE WHEN surface IN ('unpaved', 'compacted', 'dirt', 'earth', 'fine_gravel', 'grass', 'grass_paver', 'gravel', 'ground',
'mud', 'pebblestone', 'salt', 'sand', 'woodchips', 'clay', 'ice', 'snow') THEN 'unpaved'
WHEN surface IN ('paved', 'asphalt', 'cobblestone', 'cobblestone:flattened', 'sett', 'concrete', 'concrete:lanes',
WHEN surface IN ('paved', 'asphalt', 'cobblestone', 'cobblestone:flattened', 'sett', 'concrete', 'concrete:lanes',
'concrete:plates', 'paving_stones', 'metal', 'wood', 'unhewn_cobblestone') THEN 'paved'
END AS int_surface,
carto_highway_int_access(highway, access, foot, bicycle, horse, tags->'motorcar', tags->'motor_vehicle', tags->'vehicle') AS int_access,
Expand All @@ -701,7 +713,7 @@ Layer:
WHEN highway IN ('motorway_link', 'trunk_link', 'primary_link', 'secondary_link', 'tertiary_link') THEN 'yes'
ELSE 'no'
END AS link,
'no' AS preserved,
NULL AS preserved,
COALESCE(layer,0) AS layernotnull,
osm_id,
z_order
Expand All @@ -718,20 +730,15 @@ Layer:
WHEN (railway = 'tram' AND service IN ('spur', 'siding', 'yard')) THEN 'tram-service'
ELSE railway END) AS feature,
tracktype,
CASE WHEN surface IN ('unpaved', 'compacted', 'dirt', 'earth', 'fine_gravel', 'grass', 'grass_paver', 'gravel', 'ground',
'mud', 'pebblestone', 'salt', 'sand', 'woodchips', 'clay', 'ice', 'snow') THEN 'unpaved'
WHEN surface IN ('paved', 'asphalt', 'cobblestone', 'cobblestone:flattened', 'sett', 'concrete', 'concrete:lanes',
'concrete:plates', 'paving_stones', 'metal', 'wood', 'unhewn_cobblestone') THEN 'paved'
ELSE NULL
END AS int_surface,
NULL,
NULL AS int_surface,
NULL AS int_access,
construction,
CASE WHEN service IN ('parking_aisle', 'drive-through', 'driveway') OR leisure IN ('slipway') THEN 'INT-minor'::text ELSE 'INT-normal'::text END AS service,
'no' AS link,
(CASE
NULL AS service,
NULL AS link,
CASE
WHEN tags->'railway:preserved' = 'yes' THEN 'yes'
ELSE 'no'
END) AS preserved,
END AS preserved,
COALESCE(layer,0) AS layernotnull,
osm_id,
z_order
Expand Down Expand Up @@ -792,6 +799,7 @@ Layer:
<<: *extents
Datasource:
<<: *osm2pgsql
# see layer roads-casing
table: *roads_sql
properties:
cache-features: true
Expand Down Expand Up @@ -893,6 +901,14 @@ Layer:
<<: *extents
Datasource:
<<: *osm2pgsql
# NOTE: There are 3 similar queries: here and in the roads-casing and bridges layers. Any change introduced
# in this query must be considered for inclusion in the other two. Changes in the WHERE clause should be
# particularly thought through.

# This is one of the most complex layers, so it bears explaining in some detail
# It is necessary to
# - Have roads and railways in the same layer to get ordering right
# - Return two linestrings for ways which are both a road and railway
table: |-
(SELECT
way,
Expand All @@ -912,21 +928,22 @@ Layer:
tracktype,
CASE WHEN surface IN ('unpaved', 'compacted', 'dirt', 'earth', 'fine_gravel', 'grass', 'grass_paver', 'gravel', 'ground',
'mud', 'pebblestone', 'salt', 'sand', 'woodchips', 'clay', 'ice', 'snow') THEN 'unpaved'
WHEN surface IN ('paved', 'asphalt', 'cobblestone', 'cobblestone:flattened', 'sett', 'concrete', 'concrete:lanes',
WHEN surface IN ('paved', 'asphalt', 'cobblestone', 'cobblestone:flattened', 'sett', 'concrete', 'concrete:lanes',
'concrete:plates', 'paving_stones', 'metal', 'wood', 'unhewn_cobblestone') THEN 'paved'
END AS int_surface,
carto_highway_int_access(highway, access, foot, bicycle, horse, tags->'motorcar', tags->'motor_vehicle', tags->'vehicle') AS int_access,
construction,
CASE
WHEN service IN ('parking_aisle', 'drive-through', 'driveway') THEN 'INT-minor'::text
WHEN service IN ('parking_aisle', 'drive-through', 'driveway') OR leisure IN ('slipway') THEN 'INT-minor'::text
ELSE 'INT-normal'::text
END AS service,
CASE
WHEN highway IN ('motorway_link', 'trunk_link', 'primary_link', 'secondary_link', 'tertiary_link') THEN 'yes'
ELSE 'no'
END AS link,
'no' AS preserved,
NULL AS preserved,
COALESCE(layer,0) AS layernotnull,
osm_id,
z_order
FROM planet_osm_line
WHERE bridge IN ('yes', 'boardwalk', 'cantilever', 'covered', 'low_water_crossing', 'movable', 'trestle', 'viaduct')
Expand All @@ -939,16 +956,17 @@ Layer:
WHEN (railway = 'tram' AND service IN ('spur', 'siding', 'yard')) THEN 'tram-service'
ELSE railway END) AS feature,
tracktype,
'null',
NULL,
NULL AS int_surface,
NULL AS int_access,
construction,
CASE WHEN service IN ('parking_aisle', 'drive-through', 'driveway') THEN 'INT-minor'::text ELSE 'INT-normal'::text END AS service,
'no' AS link,
(CASE
NULL AS service,
NULL AS link,
CASE
WHEN tags->'railway:preserved' = 'yes' THEN 'yes'
ELSE 'no'
END) AS preserved,
END AS preserved,
COALESCE(layer,0) AS layernotnull,
osm_id,
z_order
FROM planet_osm_line
WHERE bridge IN ('yes', 'boardwalk', 'cantilever', 'covered', 'low_water_crossing', 'movable', 'trestle', 'viaduct')
Expand Down

0 comments on commit 5791e79

Please sign in to comment.