Move highway and railway into transportation

This commit is contained in:
Lukas Martinelli
2016-11-26 20:19:43 +00:00
parent c769577c56
commit 35b6951c81
23 changed files with 216 additions and 303 deletions

View File

@@ -0,0 +1,30 @@
# highway
Roads or [`highway`](http://wiki.openstreetmap.org/wiki/Key:highway) in OpenStreetMap lingo.
This layer is directly derived from the OSM road hierarchy which is why it is called `highway`. Only
at zoom level 4 to 7 some major highways from Natural Earth are used otherwise it is only OSM data.
It contains all roads from motorways to primary, secondary and tertiary roads to residential roads and
foot paths. Styling the roads is the most essential part of the map. If you can put enough effort into it
makes sense to carefully style each `subclass`. For more comfortable styling you can also just style the roads
by `class`. Roads can have different properties, a road can have `oneway=yes` and `bridge=yes` at the same time.
These properties are reflected in the field `properties`.
This layer is not meant for labelling the roads (the purpose of the layer `highway_name`).
The `highway` layer also contains polygons for things like plazas.
## Fields
- **class**: Either `motorway`, `major_road` (containing `trunk`, `primary`, `secondary` and `tertiary` roads) and `minor_road` (less important roads in the hierarchy like `residential` or `service`) or `path` for
non vehicle paths (such as `cycleway` or `footpath`).
- **subclass**: Original value of the [`highway`](http://wiki.openstreetmap.org/wiki/Key:highway) tag. Use this to do more
precise styling.
- **properties**: Additional properties describing the nature of road.
The properties `bridge` and `tunnel` can be combined with `oneway` as well. So to style all bridges the same you
should style both the properties `bridge` and `bridge:oneway`.
Properties can be one of `bridge:oneway`, `tunnel:oneway`, `ramp`, `ford`, `bridge`, `tunnel` or`oneway`.
## Mapping
![](mapping.png)

View File

@@ -0,0 +1,83 @@
CREATE OR REPLACE FUNCTION highway_is_link(highway TEXT) RETURNS BOOLEAN AS $$
SELECT highway LIKE '%_link';
$$ 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 $$
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
FROM (
-- etldoc: ne_10m_global_roads -> layer_transportation:z4z7
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,
0 AS z_order
FROM ne_10m_global_roads
WHERE zoom_level BETWEEN 4 AND 7 AND scalerank <= 1 + zoom_level
UNION ALL
-- etldoc: osm_transportation_linestring_gen4 -> layer_transportation:z8
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 = 8
UNION ALL
-- etldoc: osm_transportation_linestring_gen3 -> layer_transportation:z9
SELECT osm_id, geometry, highway, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
FROM osm_transportation_linestring_gen3
WHERE zoom_level = 9
UNION ALL
-- etldoc: osm_transportation_linestring_gen2 -> layer_transportation:z10
SELECT osm_id, geometry, highway, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
FROM osm_transportation_linestring_gen2
WHERE zoom_level = 10
UNION ALL
-- etldoc: osm_transportation_linestring_gen1 -> layer_transportation:z11
SELECT osm_id, geometry, highway, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
FROM osm_transportation_linestring_gen1
WHERE zoom_level = 11
UNION ALL
-- etldoc: osm_transportation_linestring -> layer_transportation:z12
SELECT osm_id, geometry, highway, 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) < 'minor_road'::highway_class OR highway IN ('unclassified', 'residential'))
AND NOT highway_is_link(highway)
AND NOT is_area
UNION ALL
-- etldoc: osm_transportation_linestring -> layer_transportation:z13
SELECT osm_id, geometry, highway, 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'::highway_class
AND NOT is_area
UNION ALL
-- etldoc: osm_transportation_linestring -> layer_transportation:z14_
SELECT osm_id, geometry, highway, is_bridge, is_tunnel, is_ford, is_ramp, is_oneway, z_order
FROM osm_transportation_linestring
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
-- etldoc: osm_transportation__polygon -> layer_transportation:z13
-- etldoc: osm_transportation__polygon -> layer_transportation:z14_
SELECT osm_id, geometry, highway, 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
) AS zoom_levels
WHERE geometry && bbox
ORDER BY z_order ASC;
$$ LANGUAGE SQL IMMUTABLE;

View File

@@ -0,0 +1,39 @@
digraph "Imposm Mapping" {
graph [rankdir=LR ranksep=3]
subgraph highway_polygon {
node [fixed_size=shape "width:"=20]
highway_polygon [shape=box]
key_highway [label=highway shape=box]
key_highway -> highway_polygon [label=pedestrian]
}
subgraph highway_linestring {
node [fixed_size=shape "width:"=20]
highway_linestring [shape=box]
key_highway [label=highway shape=box]
key_highway -> highway_linestring [label="motorway
motorway_link
trunk
trunk_link
primary
primary_link
secondary
secondary_link
tertiary
tertiary_link
unclassified
residential
road
living_street
raceway
construction
track
service
path
cycleway
bridleway
footway
corridor
crossing
pedestrian"]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

View File

@@ -0,0 +1,140 @@
generalized_tables:
# etldoc: imposm3 -> osm_transportation_linestring_gen4
transportation_linestring_gen4:
source: transportation_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
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
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
sql_filter: highway IN ('motorway','trunk', 'primary', 'secondary', 'tertiary') AND NOT is_area
tolerance: 20.0
tables:
# etldoc: imposm3 -> osm_transportation_linestring
transportation_linestring:
type: linestring
fields:
- name: osm_id
type: id
- name: geometry
type: geometry
- 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
mapping:
highway:
- motorway
- motorway_link
- trunk
- trunk_link
- primary
- primary_link
- secondary
- secondary_link
- tertiary
- tertiary_link
- unclassified
- residential
- road
- living_street
- raceway
- construction
- track
- service
- path
- cycleway
- bridleway
- footway
- corridor
- crossing
- pedestrian
railway:
- rail
- light_rail
- subway
- narrow_gauge
- preserved
- tram
# etldoc: imposm3 -> osm_transportation_polygon
transportation_polygon:
type: polygon
fields:
- name: osm_id
type: id
- name: geometry
type: geometry
- name: highway
key: highway
type: string
- name: z_order
type: wayzorder
- name: layer
key: layer
type: integer
- name: is_area
key: area
type: bool
mapping:
highway:
- pedestrian

View File

@@ -0,0 +1,31 @@
CREATE OR REPLACE FUNCTION ne_highway(type VARCHAR) RETURNS VARCHAR AS $$
SELECT CASE type
WHEN 'Major Highway' THEN 'motorway'
WHEN 'Secondary Highway' THEN 'trunk'
WHEN 'Road' THEN 'primary'
ELSE type
END;
$$ LANGUAGE SQL IMMUTABLE;
-- etldoc: ne_global_roads_sql -> ne_10m_global_roads ;
CREATE TABLE IF NOT EXISTS ne_10m_global_roads AS (
-- etldoc: ne_10m_roads -> ne_10m_global_roads
SELECT geom AS geometry, scalerank, ne_highway(type) AS highway
FROM ne_10m_roads
WHERE continent <> 'North America'
AND featurecla = 'Road'
AND type IN ('Major Highway', 'Secondary Highway', 'Road')
UNION ALL
-- etldoc: ne_10m_roads_north_america -> ne_10m_global_roads
SELECT geom AS geometry, scalerank, ne_highway(type) AS highway
FROM ne_10m_roads_north_america
WHERE type IN ('Major Highway', 'Secondary Highway', 'Road')
);
CREATE INDEX IF NOT EXISTS ne_10m_global_roads_geometry_idx ON ne_10m_global_roads USING gist(geometry);
CREATE INDEX IF NOT EXISTS ne_10m_global_roads_scalerank_idx ON ne_10m_global_roads(scalerank);

View File

@@ -0,0 +1,39 @@
layer:
id: "transportation"
description: |
Roads or [`highway`](http://wiki.openstreetmap.org/wiki/Key:highway) in OpenStreetMap lingo.
This layer is directly derived from the OSM road hierarchy which is why it is called `highway`. Only
at zoom level 4 to 7 some major highways from Natural Earth are used otherwise it is only OSM data.
It contains all roads from motorways to primary, secondary and tertiary roads to residential roads and
foot paths. Styling the roads is the most essential part of the map. If you can put enough effort into it
makes sense to carefully style each `subclass`. For more comfortable styling you can also just style the roads
by `class`. Roads can have different properties, a road can have `oneway=yes` and `bridge=yes` at the same time.
These properties are reflected in the field `properties`.
This layer is not meant for labelling the roads (the purpose of the layer `highway_name`).
The `highway` layer also contains polygons for things like plazas.
buffer_size: 4
srs: +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over
fields:
class: |
Either `motorway`, `major_road` (containing `trunk`, `primary`, `secondary` and `tertiary` roads) and `minor_road` (less important roads in the hierarchy like `residential` or `service`) or `path` for
non vehicle paths (such as `cycleway` or `footpath`).
subclass: |
Original value of the [`highway`](http://wiki.openstreetmap.org/wiki/Key:highway) tag. Use this to do more
precise styling.
properties: |
Additional properties describing the nature of road.
The properties `bridge` and `tunnel` can be combined with `oneway` as well. So to style all bridges the same you
should style both the properties `bridge` and `bridge:oneway`.
Properties can be one of `bridge:oneway`, `tunnel:oneway`, `ramp`, `ford`, `bridge`, `tunnel` or`oneway`.
datasource:
geometry_field: geometry
srid: 900913
query: (SELECT geometry, class::text, subclass, properties::text FROM layer_transportation(!bbox!, z(!scale_denominator!))) AS t
schema:
- ./types.sql
- ./ne_global_roads.sql
- ./highway.sql
datasources:
- type: imposm3
mapping_file: ./mapping.yaml

View File

@@ -0,0 +1,44 @@
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'highway_class') THEN
CREATE TYPE highway_class AS ENUM ('motorway', 'major_road', 'minor_road', 'path');
END IF;
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_highway_class(highway TEXT) RETURNS highway_class AS $$
SELECT CASE
WHEN highway IN ('motorway', 'motorway_link') THEN 'motorway'::highway_class
-- 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'::highway_class
WHEN highway IN ('unclassified', 'residential', 'living_street', 'road', 'track', 'service') THEN 'minor_road'::highway_class
WHEN highway IN ('pedestrian', 'path', 'footway', 'cycleway', 'steps') THEN 'path'::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;