generalized_tables:
# etldoc: osm_railway_linestring_gen_z9 -> osm_railway_linestring_gen_z8
  railway_linestring_gen_z8:
    source: railway_linestring_gen_z9
    tolerance: ZRES9

# etldoc: osm_railway_linestring_gen_z10 -> osm_railway_linestring_gen_z9
  railway_linestring_gen_z9:
    source: railway_linestring_gen_z10
    tolerance: ZRES10

# etldoc: osm_railway_linestring_gen_z11 -> osm_railway_linestring_gen_z10
  railway_linestring_gen_z10:
    source: railway_linestring_gen_z11
    tolerance: ZRES11

# etldoc: osm_railway_linestring_gen_z12 -> osm_railway_linestring_gen_z11
  railway_linestring_gen_z11:
    source: railway_linestring_gen_z12
    tolerance: ZRES12

# etldoc: osm_railway_linestring -> osm_railway_linestring_gen_z12
  railway_linestring_gen_z12:
    source: railway_linestring
    sql_filter: railway IN ('rail', 'narrow_gauge', 'light_rail') AND service='' AND ST_IsValid(geometry)
    tolerance: ZRES13

# etldoc: osm_aerialway_linestring -> osm_aerialway_linestring_gen_z12
  aerialway_linestring_gen_z12:
    source: aerialway_linestring
    sql_filter: ST_IsValid(geometry)
    tolerance: ZRES13

# etldoc: osm_shipway_linestring_gen_z5 -> osm_shipway_linestring_gen_z4
  shipway_linestring_gen_z4:
    source: shipway_linestring_gen_z5
    sql_filter: ST_Length(geometry)>2*ZRES0
    tolerance: ZRES5

# etldoc: osm_shipway_linestring_gen_z6 -> osm_shipway_linestring_gen_z5
  shipway_linestring_gen_z5:
    source: shipway_linestring_gen_z6
    sql_filter: ST_Length(geometry)>ZRES0
    tolerance: ZRES6

# etldoc: osm_shipway_linestring_gen_z7 -> osm_shipway_linestring_gen_z6
  shipway_linestring_gen_z6:
    source: shipway_linestring_gen_z7
    sql_filter: ST_Length(geometry)>ZRES1
    tolerance: ZRES7

# etldoc: osm_shipway_linestring_gen_z8 -> osm_shipway_linestring_gen_z7
  shipway_linestring_gen_z7:
    source: shipway_linestring_gen_z8
    sql_filter: ST_Length(geometry)>ZRES2
    tolerance: ZRES8

# etldoc: osm_shipway_linestring_gen_z9 -> osm_shipway_linestring_gen_z8
  shipway_linestring_gen_z8:
    source: shipway_linestring_gen_z9
    sql_filter: ST_Length(geometry)>ZRES3
    tolerance: ZRES9

# etldoc: osm_shipway_linestring_gen_z10 -> osm_shipway_linestring_gen_z9
  shipway_linestring_gen_z9:
    source: shipway_linestring_gen_z10
    sql_filter: ST_Length(geometry)>ZRES4
    tolerance: ZRES10

# etldoc: osm_shipway_linestring_gen_z11 -> osm_shipway_linestring_gen_z10
  shipway_linestring_gen_z10:
    source: shipway_linestring_gen_z11
    sql_filter: ST_Length(geometry)>ZRES5
    tolerance: ZRES11

# etldoc: osm_shipway_linestring_gen_z12 -> osm_shipway_linestring_gen_z11
  shipway_linestring_gen_z11:
    source: shipway_linestring_gen_z12
    tolerance: ZRES12

# etldoc: osm_shipway_linestring -> osm_shipway_linestring_gen_z12
  shipway_linestring_gen_z12:
    source: shipway_linestring
    sql_filter: ST_IsValid(geometry)
    tolerance: ZRES13

# etldoc: osm_highway_linestring -> osm_highway_linestring_gen_z11
  highway_linestring_gen_z11:
    source: highway_linestring
    sql_filter: (highway IN ('motorway', 'trunk', 'primary', 'secondary', 'tertiary', 'motorway_link', 'trunk_link', 'primary_link', 'secondary_link', 'tertiary_link', 'busway', 'bus_guideway') OR highway = 'construction' AND construction IN ('motorway', 'trunk', 'primary', 'secondary', 'tertiary', 'motorway_link', 'trunk_link', 'primary_link', 'secondary_link', 'tertiary_link', 'busway', 'bus_guideway')) AND NOT is_area AND ST_IsValid(geometry)
    tolerance: ZRES12

name_field: &name
  name: name
  key: name
  type: string
name_en_field: &name_en
  name: name_en
  key: name:en
  type: string
name_de_field: &name_de
  name: name_de
  key: name:de
  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: direction
area_field: &area
  name: is_area
  key: area
  type: bool
service_field: &service
  key: service
  name: service
  type: string
access_field: &access
  key: access
  name: access
  type: string
toll_field: &toll
  key: toll
  name: toll
  type: bool
usage_field: &usage
  key: usage
  name: usage
  type: string
public_transport_field: &public_transport
  key: public_transport
  name: public_transport
  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
level_field: &level
  key: level
  name: level
  type: integer
indoor_field: &indoor
  key: indoor
  name: indoor
  type: bool
man_made_field: &man_made
  key: man_made
  name: man_made
  type: string
z_order_field: &z_order
  name: z_order
  type: wayzorder
bicycle_field: &bicycle
  key: bicycle
  name: bicycle
  type: string
foot_field: &foot
  key: foot
  name: foot
  type: string
horse_field: &horse
  key: horse
  name: horse
  type: string
mtb_scale_field: &mtb_scale
  key: mtb:scale
  name: mtb_scale
  type: string
sac_scale_field: &sac_scale
  key: sac_scale
  name: sac_scale
  type: string
operator_field: &operator
  key: operator
  name: operator
  type: string
informal_field: &informal
  key: informal
  name: informal
  type: string
surface_field: &surface
  key: surface
  name: surface
  type: string
expressway_field: &expressway
  key: expressway
  name: expressway
  type: bool

tables:
# etldoc: imposm3 -> osm_highway_linestring
  highway_linestring:
    type: linestring
    _resolve_wikidata: false
    columns:
    - name: osm_id
      type: id
    - name: geometry
      type: geometry
    - name: highway
      key: highway
      type: string
    - name: construction
      key: construction
      type: string
    - name: tracktype
      key: tracktype
      type: string
    - *ref
    - *network
    - *z_order
    - *layer
    - *level
    - *indoor
    - *name
    - *name_en
    - *name_de
    - name: tags
      type: hstore_tags
    - *tunnel
    - *bridge
    - *ramp
    - *ford
    - *oneway
    - *area
    - *service
    - *access
    - *toll
    - *usage
    - *public_transport
    - *man_made
    - *bicycle
    - *foot
    - *horse
    - *mtb_scale
    - *sac_scale
    - *operator
    - *informal
    - *surface
    - *expressway
    mapping:
      highway:
      - motorway
      - motorway_link
      - trunk
      - trunk_link
      - primary
      - primary_link
      - secondary
      - secondary_link
      - tertiary
      - tertiary_link
      - unclassified
      - residential
      - living_street
      - road
      - pedestrian
      - path
      - footway
      - cycleway
      - steps
      - bridleway
      - corridor
      - service
      - track
      - raceway
      - busway
      - bus_guideway
      - construction
      public_transport:
      - platform
      man_made:
      - pier
      service:
      - driveway
      - parking_aisle

# etldoc: imposm3 -> osm_railway_linestring
  railway_linestring:
    type: linestring
    _resolve_wikidata: false
    columns:
    - name: osm_id
      type: id
    - name: geometry
      type: geometry
    - key: railway
      name: railway
      type: string
    - *ref
    - *network
    - *z_order
    - *layer
    - *level
    - *indoor
    - *name
    - *name_en
    - *name_de
    - name: tags
      type: hstore_tags
    - *tunnel
    - *bridge
    - *ramp
    - *ford
    - *area
    - *service
    - *usage
    mapping:
      railway:
      - rail
      - narrow_gauge
      - preserved
      - funicular
      - subway
      - light_rail
      - monorail
      - tram

# etldoc: imposm3 -> osm_aerialway_linestring
  aerialway_linestring:
    type: linestring
    _resolve_wikidata: false
    columns:
    - name: osm_id
      type: id
    - name: geometry
      type: geometry
    - key: aerialway
      name: aerialway
      type: string
    - *z_order
    - *layer
    - *name
    - *name_en
    - *name_de
    - name: tags
      type: hstore_tags
    - *tunnel
    - *bridge
    - *ramp
    - *ford
    - *oneway
    - *area
    - *service
    - *usage
    mapping:
      aerialway:
      - chair_lift
      - drag_lift
      - platter
      - t-bar
      - gondola
      - cable_car
      - j-bar
      - mixed_lift

# etldoc: imposm3 -> osm_shipway_linestring
  shipway_linestring:
    type: linestring
    _resolve_wikidata: false
    columns:
    - name: osm_id
      type: id
    - name: geometry
      type: geometry
    - key: route
      name: shipway
      type: string
    - *z_order
    - *layer
    - *name
    - *name_en
    - *name_de
    - name: tags
      type: hstore_tags
    - *tunnel
    - *bridge
    - *ramp
    - *ford
    - *area
    - *service
    - *usage
    mapping:
      route:
      - ferry

# etldoc: imposm3 -> osm_highway_polygon
  highway_polygon:
    type: polygon
    columns:
    - name: osm_id
      type: id
    - name: geometry
      type: geometry
    - name: highway
      key: highway
      type: string
    - name: z_order
      type: wayzorder
    - *layer
    - *level
    - *indoor
    - name: is_area
      key: area
      type: bool
    - *public_transport
    - *man_made
    - *service
    mapping:
      highway:
      - path
      - cycleway
      - bridleway
      - footway
      - corridor
      - pedestrian
      - steps
      public_transport:
      - platform
      man_made:
      - bridge
      - pier

  # etldoc: imposm3 -> highway_point
  highway_point:
    type: point
    columns:
    - name: osm_id
      type: id
    - name: geometry
      type: geometry
    - name: highway
      key: highway
      type: string
    - name: z_order
      type: wayzorder
    - *layer
    - *level
    - *name
    - *name_en
    - *name_de
    - name: tags
      type: hstore_tags
    - name: ref
      key: ref
      type: string
    mapping:
      highway:
      - motorway_junction

# 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
    - *name
    - name: osmc_symbol
      key: osmc:symbol
      type: string
    - name: colour
      key: colour
      type: string
    - name: ref_colour
      key: ref:colour
      type: string
    mapping:
      route:
      - road
      - hiking
