Split railway and highway into different tables

pull/60/head
Lukas Martinelli 2016-11-28 12:50:04 +00:00
rodzic de2f538ef5
commit 1d3171185b
3 zmienionych plików z 181 dodań i 103 usunięć

Wyświetl plik

@ -6,18 +6,19 @@ $$ 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 text, subclass text, ramp int, oneway int, brunnel TEXT) AS $$
RETURNS TABLE(osm_id bigint, geometry geometry, class text, subclass text, ramp int, oneway int, brunnel TEXT, service TEXT) AS $$
SELECT
osm_id, geometry,
CASE
WHEN highway <> '' THEN highway_class(highway)
WHEN railway <> '' THEN railway_class(railway)
WHEN highway IS NULL THEN highway_class(highway)
WHEN railway IS NULL 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,
brunnel(is_bridge, is_tunnel, is_ford) AS brunnel
brunnel(is_bridge, is_tunnel, is_ford) AS brunnel,
NULLIF(service, '') AS service
FROM (
-- etldoc: ne_10m_global_roads -> layer_transportation:z4z6
SELECT
@ -30,80 +31,77 @@ RETURNS TABLE(osm_id bigint, geometry geometry, class text, subclass text, ramp
WHERE zoom_level BETWEEN 4 AND 6 AND scalerank <= 1 + zoom_level
UNION ALL
-- etldoc: osm_transportation_linestring_gen4 -> layer_transportation:z7z8
-- etldoc: osm_highway_linestring_gen4 -> layer_transportation:z7z8
SELECT
osm_id, geometry, highway, railway, service,
osm_id, geometry, highway, NULL AS railway, service,
is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
FROM osm_transportation_linestring_gen4
FROM osm_highway_linestring_gen4
WHERE zoom_level BETWEEN 7 AND 8
UNION ALL
-- etldoc: osm_transportation_linestring_gen3 -> layer_transportation:z9
-- etldoc: osm_highway_linestring_gen3 -> layer_transportation:z9
SELECT
osm_id, geometry, highway, railway, service,
osm_id, geometry, highway, NULL AS railway, service,
is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
FROM osm_transportation_linestring_gen3
FROM osm_highway_linestring_gen3
WHERE zoom_level = 9
UNION ALL
-- etldoc: osm_transportation_linestring_gen2 -> layer_transportation:z10
-- etldoc: osm_highway_linestring_gen2 -> layer_transportation:z10
SELECT
osm_id, geometry, highway, railway, service,
osm_id, geometry, highway, NULL AS railway, service,
is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
FROM osm_transportation_linestring_gen2
FROM osm_highway_linestring_gen2
WHERE zoom_level = 10
UNION ALL
-- etldoc: osm_transportation_linestring_gen1 -> layer_transportation:z11
-- etldoc: osm_highway_linestring_gen1 -> layer_transportation:z11
SELECT
osm_id, geometry, highway, railway, service,
osm_id, geometry, highway, NULL AS railway, service,
is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
FROM osm_transportation_linestring_gen1
FROM osm_highway_linestring_gen1
WHERE zoom_level = 11
UNION ALL
-- etldoc: osm_transportation_linestring -> layer_transportation:z12
-- etldoc: osm_highway_linestring -> layer_transportation:z12
-- etldoc: osm_highway_linestring -> layer_transportation:z13
-- etldoc: osm_highway_linestring -> layer_transportation:z14_
SELECT
osm_id, geometry, highway, railway, service,
osm_id, geometry, highway, NULL AS railway, service,
is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
FROM osm_transportation_linestring
WHERE zoom_level = 12
AND (
FROM osm_highway_linestring
WHERE NOT is_area AND (
zoom_level = 12 AND (
highway_class(highway) NOT IN ('track', 'path', 'minor')
OR highway IN ('unclassified', 'residential')
)
AND NOT is_area
OR zoom_level = 13 AND highway_class(highway) NOT IN ('track', 'path')
OR zoom_level >= 14
)
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
FROM osm_transportation_linestring
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
FROM osm_transportation_linestring
WHERE zoom_level >= 14 AND NOT is_area
-- etldoc: osm_railway_linestring -> layer_transportation:z13
-- etldoc: osm_railway_linestring -> layer_transportation:z14
SELECT
osm_id, geometry, NULL AS highway, railway, service,
is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
FROM osm_railway_linestring
WHERE zoom_level = 13 AND (railway='rail' AND service = '')
OR zoom_Level >= 14
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
-- etldoc: osm_transportation__polygon -> layer_transportation:z13
-- etldoc: osm_transportation__polygon -> layer_transportation:z14_
-- etldoc: osm_highway_polygon -> layer_transportation:z13
-- etldoc: osm_highway_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
FROM osm_transportation_polygon
FROM osm_highway_polygon
-- We do not want underground pedestrian areas for now
WHERE zoom_level >= 13 AND is_area AND COALESCE(layer, 0) >= 0
) AS zoom_levels

Wyświetl plik

@ -1,33 +1,93 @@
generalized_tables:
# etldoc: imposm3 -> osm_transportation_linestring_gen4
transportation_linestring_gen4:
source: transportation_linestring_gen3
# etldoc: imposm3 -> osm_highway_linestring_gen4
highway_linestring_gen4:
source: highway_linestring_gen3
sql_filter: highway IN ('motorway','trunk') AND NOT is_area
tolerance: 200.0
# etldoc: imposm3 -> osm_transportation_linestring_gen3
transportation_linestring_gen3:
source: transportation_linestring_gen2
# etldoc: imposm3 -> osm_highway_linestring_gen3
highway_linestring_gen3:
source: highway_linestring_gen2
sql_filter: highway IN ('motorway','trunk', 'primary') AND NOT is_area
tolerance: 120.0
# etldoc: imposm3 -> osm_transportation_linestring_gen2
transportation_linestring_gen2:
source: transportation_linestring_gen1
# etldoc: imposm3 -> osm_highway_linestring_gen2
highway_linestring_gen2:
source: highway_linestring_gen1
sql_filter: highway IN ('motorway','trunk', 'primary', 'secondary') AND NOT is_area
tolerance: 50.0
# etldoc: imposm3 -> osm_transportation_linestring_gen1
transportation_linestring_gen1:
source: transportation_linestring
# etldoc: imposm3 -> osm_highway_linestring_gen1
highway_linestring_gen1:
source: highway_linestring
sql_filter: highway IN ('motorway','trunk', 'primary', 'secondary', 'tertiary') AND NOT is_area
tolerance: 20.0
name_field: &name
name: name
key: name
type: string
name_en_field: &name_en
name: name_en
key: name:en
type: string
short_name_field: &short_name
key: short_name
name: short_name
type: string
tunnel_field: &tunnel
key: tunnel
name: is_tunnel
type: bool
bridge_field: &bridge
key: bridge
name: is_bridge
type: bool
ramp_field: &ramp
key: ramp
name: is_ramp
type: bool
ford_field: &ford
key: ford
name: is_ford
type: bool
oneway_field: &oneway
key: oneway
name: is_oneway
type: bool
area_field: &area
name: is_area
key: area
type: bool
service_field: &service
key: service
name: service
type: string
usage_field: &usage
key: usage
name: usage
type: string
ref_field: &ref
key: ref
name: ref
type: string
network_field: &network
key: network
name: network
type: string
layer_field: &layer
key: layer
name: layer
type: integer
z_order_field: &z_order
name: z_order
type: wayzorder
tables:
# etldoc: imposm3 -> osm_transportation_linestring
transportation_linestring:
# etldoc: imposm3 -> osm_highway_linestring
highway_linestring:
type: linestring
fields:
- name: osm_id
@ -37,50 +97,21 @@ tables:
- name: highway
key: highway
type: string
- key: railway
name: railway
type: string
- key: ref
name: ref
type: string
- name: z_order
type: wayzorder
- name: layer
key: layer
type: integer
- key: tunnel
name: is_tunnel
type: bool
- key: bridge
name: is_bridge
type: bool
- key: ramp
name: is_ramp
type: bool
- key: ford
name: is_ford
type: bool
- key: oneway
name: is_oneway
type: bool
- key: name
name: name
type: string
- key: short_name
name: short_name
type: string
- name: name_en
key: name:en
type: string
- name: is_area
key: area
type: bool
- key: service
name: service
type: string
- key: usage
name: usage
type: string
- *ref
- *network
- *z_order
- *layer
- *name
- *name_en
- *short_name
- *tunnel
- *bridge
- *ramp
- *ford
- *oneway
- *area
- *service
- *usage
mapping:
highway:
- motorway
@ -108,16 +139,46 @@ tables:
- corridor
- crossing
- pedestrian
# etldoc: imposm3 -> osm_railway_linestring
railway_linestring:
type: linestring
fields:
- name: osm_id
type: id
- name: geometry
type: geometry
- key: railway
name: railway
type: string
- *ref
- *network
- *z_order
- *layer
- *name
- *name_en
- *short_name
- *tunnel
- *bridge
- *ramp
- *ford
- *oneway
- *area
- *service
- *usage
mapping:
railway:
- rail
- light_rail
- subway
- narrow_gauge
- preserved
- funicular
- subway
- light_rail
- monorail
- tram
# etldoc: imposm3 -> osm_transportation_polygon
transportation_polygon:
# etldoc: imposm3 -> osm_highway_polygon
highway_polygon:
type: polygon
fields:
- name: osm_id
@ -138,3 +199,22 @@ tables:
mapping:
highway:
- pedestrian
# TODO: Future table for joining networks
# etldoc: imposm3 -> osm_route_member
route_member:
type: relation_member
columns:
- name: osm_id
type: id
- name: member
type: member_id
- name: role
type: member_role
- name: type
type: member_type
- *ref
- *network
mapping:
route:
- road

Wyświetl plik

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