Add ramp, oneway, brunnel to transportation

pull/60/head
Lukas Martinelli 2016-11-26 20:46:19 +00:00
rodzic 453d64ba17
commit 69b77416be
3 zmienionych plików z 15 dodań i 25 usunięć

Wyświetl plik

@ -6,14 +6,16 @@ $$ LANGUAGE SQL IMMUTABLE STRICT;
-- etldoc: layer_transportation[shape=record fillcolor=lightpink, style="rounded,filled",
-- etldoc: label="<sql> layer_transportation |<z4z7> z4-z7 |<z8> z8 |<z9> z9 |<z10> z10 |<z11> z11 |<z12> z12|<z13> z13|<z14_> z14_" ] ;
CREATE OR REPLACE FUNCTION layer_transportation(bbox geometry, zoom_level int)
RETURNS TABLE(osm_id bigint, geometry geometry, class highway_class, subclass text, properties highway_properties) AS $$
RETURNS TABLE(osm_id bigint, geometry geometry, class highway_class, subclass text, ramp int, oneway int, brunnel TEXT) AS $$
SELECT
osm_id, geometry,
to_highway_class(highway) AS class, highway AS subclass,
to_highway_properties(is_bridge, is_tunnel, is_ford, is_ramp, is_oneway) AS properties
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 (
-- etldoc: ne_10m_global_roads -> layer_transportation:z4z7
-- etldoc: ne_10m_global_roads -> layer_transportation:z4z6
SELECT
NULL::bigint AS osm_id, geometry, highway,
FALSE AS is_bridge, FALSE AS is_tunnel, FALSE AS is_ford, FALSE AS is_ramp, FALSE AS is_oneway,
@ -22,7 +24,7 @@ RETURNS TABLE(osm_id bigint, geometry geometry, class highway_class, subclass te
WHERE zoom_level BETWEEN 4 AND 6 AND scalerank <= 1 + zoom_level
UNION ALL
-- etldoc: osm_transportation_linestring_gen4 -> layer_transportation:z8
-- etldoc: osm_transportation_linestring_gen4 -> layer_transportation:z7z8
SELECT osm_id, geometry, highway, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
FROM osm_transportation_linestring_gen4
WHERE zoom_level BETWEEN 7 AND 8

Wyświetl plik

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

Wyświetl plik

@ -8,13 +8,14 @@ BEGIN
END
$$;
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'highway_properties') THEN
CREATE TYPE highway_properties AS ENUM ('bridge:oneway', 'tunnel:oneway', 'ramp', 'ford', 'bridge', 'tunnel', 'oneway');
END IF;
END
$$;
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 highway_class AS $$
SELECT CASE
@ -29,16 +30,3 @@ CREATE OR REPLACE FUNCTION to_highway_class(highway TEXT) RETURNS highway_class
ELSE NULL
END;
$$ LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION to_highway_properties(is_bridge boolean, is_tunnel boolean, is_ford boolean, is_ramp boolean, is_oneway boolean) RETURNS highway_properties AS $$
SELECT CASE
WHEN is_bridge AND is_oneway THEN 'bridge:oneway'::highway_properties
WHEN is_tunnel AND is_oneway THEN 'tunnel:oneway'::highway_properties
WHEN is_ramp THEN 'ramp'::highway_properties
WHEN is_ford THEN 'ford'::highway_properties
WHEN is_bridge THEN 'bridge'::highway_properties
WHEN is_tunnel THEN 'tunnel'::highway_properties
WHEN is_oneway THEN 'oneway'::highway_properties
ELSE NULL
END;
$$ LANGUAGE SQL IMMUTABLE;