Use ClearTables scheme for classes

pull/60/head
Lukas Martinelli 2016-11-28 10:29:00 +00:00
rodzic 65419bdb84
commit a04d5776e6
4 zmienionych plików z 105 dodań i 77 usunięć

Wyświetl plik

@ -0,0 +1,34 @@
CREATE OR REPLACE FUNCTION brunnel(is_bridge BOOL, is_tunnel BOOL, is_ford BOOL) RETURNS TEXT AS $$
SELECT CASE
WHEN is_bridge THEN 'bridge'
WHEN is_tunnel THEN 'tunnel'
WHEN is_ford THEN 'ford'
ELSE NULL
END;
$$ LANGUAGE SQL IMMUTABLE STRICT;
-- The classes for highways are derived from the classes used in ClearTables
-- https://github.com/ClearTables/ClearTables/blob/master/transportation.lua
CREATE OR REPLACE FUNCTION highway_class(highway TEXT) RETURNS TEXT AS $$
SELECT CASE
WHEN highway IN ('motorway', 'motorway_link') THEN 'motorway'
WHEN highway IN ('trunk', 'trunk_link') THEN 'trunk'
WHEN highway IN ('primary', 'primary_link') THEN 'primary'
WHEN highway IN ('secondary', 'secondary_link') THEN 'secondary'
WHEN highway IN ('tertiary', 'tertiary_link') THEN 'tertiary'
WHEN highway IN ('unclassified', 'residential', 'living_street', 'road') THEN 'minor'
WHEN highway IN ('service', 'track') THEN highway
WHEN highway IN ('pedestrian', 'path', 'footway', 'cycleway', 'steps') THEN 'path'
ELSE NULL
END;
$$ LANGUAGE SQL IMMUTABLE STRICT;
-- The classes for railways are derived from the classes used in ClearTables
-- https://github.com/ClearTables/ClearTables/blob/master/transportation.lua
CREATE OR REPLACE FUNCTION railway_class(railway TEXT) RETURNS TEXT AS $$
SELECT CASE
WHEN railway IN ('rail', 'narrow_gauge', 'preserved', 'funicular') THEN 'rail'
WHEN railway IN ('subway', 'light_rail', 'monorail', 'tram') THEN 'transit'
ELSE NULL
END;
$$ LANGUAGE SQL IMMUTABLE STRICT;

Wyświetl plik

@ -8,81 +8,104 @@ $$ 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) AS $$
SELECT
osm_id, geometry,
CASE
WHEN highway <> '' THEN to_highway_class(highway)
WHEN railway <> '' THEN railway_class(railway, service)
osm_id, geometry,
CASE
WHEN highway <> '' THEN highway_class(highway)
WHEN railway <> '' THEN railway_class(railway)
END AS class,
COALESCE(NULLIF(highway,''), NULLIF(railway, '')) AS subclass,
-- All links are considered as ramps as well
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
FROM (
brunnel(is_bridge, is_tunnel, is_ford) AS brunnel
FROM (
-- etldoc: ne_10m_global_roads -> layer_transportation:z4z6
SELECT
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
WHERE zoom_level BETWEEN 4 AND 6 AND scalerank <= 1 + zoom_level
UNION ALL
-- etldoc: ne_10m_global_roads -> layer_transportation:z4z6
SELECT
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
WHERE zoom_level BETWEEN 4 AND 6 AND scalerank <= 1 + zoom_level
UNION ALL
-- etldoc: osm_transportation_linestring_gen4 -> layer_transportation:z7z8
SELECT osm_id, geometry, highway, railway, service, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
-- etldoc: osm_transportation_linestring_gen4 -> layer_transportation:z7z8
SELECT
osm_id, geometry, highway, railway, 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
WHERE zoom_level BETWEEN 7 AND 8
UNION ALL
-- etldoc: osm_transportation_linestring_gen3 -> layer_transportation:z9
SELECT osm_id, geometry, highway, railway, service, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
-- etldoc: osm_transportation_linestring_gen3 -> layer_transportation:z9
SELECT
osm_id, geometry, highway, railway, service,
is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
FROM osm_transportation_linestring_gen3
WHERE zoom_level = 9
UNION ALL
WHERE zoom_level = 9
UNION ALL
-- etldoc: osm_transportation_linestring_gen2 -> layer_transportation:z10
SELECT osm_id, geometry, highway, railway, service, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
-- etldoc: osm_transportation_linestring_gen2 -> layer_transportation:z10
SELECT
osm_id, geometry, highway, railway, service,
is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
FROM osm_transportation_linestring_gen2
WHERE zoom_level = 10
UNION ALL
WHERE zoom_level = 10
UNION ALL
-- etldoc: osm_transportation_linestring_gen1 -> layer_transportation:z11
SELECT osm_id, geometry, highway, railway, service, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
-- etldoc: osm_transportation_linestring_gen1 -> layer_transportation:z11
SELECT
osm_id, geometry, highway, railway, service,
is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
FROM osm_transportation_linestring_gen1
WHERE zoom_level = 11
UNION ALL
WHERE zoom_level = 11
UNION ALL
-- etldoc: osm_transportation_linestring -> layer_transportation:z12
SELECT osm_id, geometry, highway, railway, service, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
-- etldoc: osm_transportation_linestring -> layer_transportation:z12
SELECT
osm_id, geometry, highway, railway, 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) NOT IN ('minor_road', 'path') OR highway IN ('unclassified', 'residential'))
AND NOT highway_is_link(highway)
WHERE zoom_level = 12
AND (
highway_class(highway) NOT IN ('track', 'path', 'minor')
OR highway IN ('unclassified', 'residential')
)
AND NOT is_area
UNION ALL
-- etldoc: osm_transportation_linestring -> layer_transportation:z13
SELECT osm_id, geometry, highway, railway, service, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
-- etldoc: osm_transportation_linestring -> layer_transportation:z13
SELECT osm_id, geometry, highway, railway, 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' OR railway_class(railway, service) = 'rail')
WHERE zoom_level = 13
AND (
highway_class(highway) NOT IN ('track', 'path')
OR (railway='rail' AND service = '')
)
AND NOT is_area
UNION ALL
-- etldoc: osm_transportation_linestring -> layer_transportation:z14_
SELECT osm_id, geometry, highway, railway, service, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
-- etldoc: osm_transportation_linestring -> layer_transportation:z14_
SELECT osm_id, geometry, highway, railway, 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
WHERE zoom_level >= 14 AND NOT is_area
UNION ALL
-- NOTE: We limit the selection of polys because we need to be careful to net get false positives here because
-- it is possible that closed linestrings appear both as highway linestrings and as polygon
-- NOTE: We limit the selection of polys because we need to be
-- careful to net get false positives here because
-- 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, 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
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
WHERE zoom_level >= 13 AND is_area AND COALESCE(layer, 0) >= 0
) AS zoom_levels
WHERE geometry && bbox
ORDER BY z_order ASC;

Wyświetl plik

@ -31,7 +31,7 @@ layer:
srid: 900913
query: (SELECT geometry, class, subclass, oneway, ramp, brunnel FROM layer_transportation(!bbox!, z(!scale_denominator!))) AS t
schema:
- ./types.sql
- ./class.sql
- ./ne_global_roads.sql
- ./layer.sql
datasources:

Wyświetl plik

@ -1,29 +0,0 @@
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'
WHEN is_tunnel THEN 'tunnel'
WHEN is_ford THEN 'ford'
ELSE NULL
END;
$$ LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION to_highway_class(highway TEXT) RETURNS TEXT AS $$
SELECT CASE
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'
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;