Skip to content

Instantly share code, notes, and snippets.

@aaronlidman
Created June 19, 2012 18:57
Show Gist options
  • Save aaronlidman/2955889 to your computer and use it in GitHub Desktop.
Save aaronlidman/2955889 to your computer and use it in GitHub Desktop.
z15+
(SELECT way, highway, railway, tunnel, bridge, layer,
(CASE
WHEN highway IN ('motorway', 'motorway_link') THEN 'highway'
WHEN highway IN ('trunk', 'trunk_link', 'primary', 'primary_link', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link') THEN 'major_road'
WHEN highway IN ('footpath', 'track', 'footway', 'steps', 'pedestrian', 'path', 'cycleway') THEN 'path'
WHEN railway IN ('rail', 'tram', 'light_rail', 'narrow_guage', 'monorail') THEN 'rail'
ELSE 'minor_road' END) AS kind,
(CASE WHEN highway LIKE '%_link' THEN 'yes'
ELSE 'no' END) AS is_link,
(CASE WHEN tunnel IN ('yes', 'true') THEN 'yes'
ELSE 'no' END) AS is_tunnel,
(CASE WHEN bridge IN ('yes', 'true') THEN 'yes'
ELSE 'no' END) AS is_bridge,
(CASE WHEN layer ~ E'^-?[[:digit:]]+(\.[[:digit:]]+)?$' THEN CAST (layer AS FLOAT)
ELSE 0
END) AS explicit_layer,
(CASE WHEN tunnel in ('yes', 'true') THEN -1
WHEN bridge in ('yes', 'true') THEN 1
ELSE 0
END) AS implied_layer,
(CASE WHEN highway IN ('motorway') THEN 0
WHEN railway IN ('rail', 'tram', 'light_rail', 'narrow_guage', 'monorail') THEN .5
WHEN highway IN ('trunk') THEN 1
WHEN highway IN ('primary') THEN 2
WHEN highway IN ('secondary') THEN 3
WHEN highway IN ('tertiary') THEN 4
WHEN highway LIKE '%_link' THEN 5
WHEN highway IN ('residential', 'unclassified', 'road') THEN 6
WHEN highway IN ('unclassified', 'service', 'minor') THEN 7
ELSE 99 END) AS priority
FROM planet_osm_line
WHERE
highway IN ('motorway', 'motorway_link')
OR highway IN ('trunk', 'trunk_link', 'primary', 'primary_link', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link')
OR highway IN ('residential', 'unclassified', 'road', 'unclassified', 'service', 'minor')
OR highway IN ('footpath', 'track', 'footway', 'steps', 'pedestrian', 'path', 'cycleway')
OR railway IN ('rail', 'tram', 'light_rail', 'narrow_guage', 'monorail')
ORDER BY explicit_layer ASC, implied_layer ASC, priority DESC
) AS roads
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment