generalized_tables:
  # etldoc: osm_border_linestring -> osm_border_disp_linestring
  border_disp_linestring:
    source: border_linestring
    sql_filter: ST_GeometryType(geometry) = 'ST_LineString' AND (disputed OR dispute OR border_status = 'disputed' OR disputed_by <> '') AND admin_level = 2

  # etldoc: osm_boundary_polygon_gen_z5 -> osm_boundary_polygon_gen_z4
  boundary_polygon_gen_z4:
    source: boundary_polygon_gen_z5
    sql_filter: area>power(ZRES3,2)
    tolerance: ZRES4

  # etldoc: osm_boundary_polygon_gen_z6 -> osm_boundary_polygon_gen_z5
  boundary_polygon_gen_z5:
    source: boundary_polygon_gen_z6
    sql_filter: area>power(ZRES4,2)
    tolerance: ZRES5

  # etldoc: osm_boundary_polygon_gen_z7 -> osm_boundary_polygon_gen_z6
  boundary_polygon_gen_z6:
    source: boundary_polygon_gen_z7
    sql_filter: area>power(ZRES5,2)
    tolerance: ZRES6

  # etldoc: osm_boundary_polygon_gen_z8 -> osm_boundary_polygon_gen_z7
  boundary_polygon_gen_z7:
    source: boundary_polygon_gen_z8
    sql_filter: area>power(ZRES6,2)
    tolerance: ZRES7

  # etldoc: osm_boundary_polygon_gen_z9 -> osm_boundary_polygon_gen_z8
  boundary_polygon_gen_z8:
    source: boundary_polygon_gen_z9
    sql_filter: area>power(ZRES7,2)
    tolerance: ZRES8

  # etldoc: osm_boundary_polygon_gen_z10 -> osm_boundary_polygon_gen_z9
  boundary_polygon_gen_z9:
    source: boundary_polygon_gen_z10
    sql_filter: area>power(ZRES8,2)
    tolerance: ZRES9

  # etldoc: osm_boundary_polygon_gen_z11 -> osm_boundary_polygon_gen_z10
  boundary_polygon_gen_z10:
    source: boundary_polygon_gen_z11
    sql_filter: area>power(ZRES9,2)
    tolerance: ZRES10

  # etldoc: osm_boundary_polygon_gen_z12 -> osm_boundary_polygon_gen_z11
  boundary_polygon_gen_z11:
    source: boundary_polygon_gen_z12
    sql_filter: area>power(ZRES10,2)
    tolerance: ZRES11

  # etldoc: osm_boundary_polygon_gen_z13 -> osm_boundary_polygon_gen_z12
  boundary_polygon_gen_z12:
    source: boundary_polygon_gen_z13
    sql_filter: area>power(ZRES11,2)
    tolerance: ZRES12

  # etldoc: osm_boundary_polygon -> osm_boundary_polygon_gen_z13
  boundary_polygon_gen_z13:
    source: boundary_polygon
    sql_filter: area>power(ZRES12,2) AND ST_IsValid(geometry)
    tolerance: ZRES13


tables:
  # etldoc: imposm3 -> osm_border_linestring
  border_linestring:
    type: relation_member
    filters:
      require:
        admin_level: [__any__]
        boundary: [administrative]
    columns:
    - name: relation_id
      type: id
    - name: osm_id
      type: id
      from_member: true
    - name: member
      type: member_id
    - name: type
      type: member_type
    - name: geometry
      type: geometry
    - key: name
      name: name
      type: string
      # Used for disputed boundary, e.g. "Line of actual control"
      from_member: true
    - key: admin_level
      name: admin_level
      type: integer
    - key: claimed_by
      name: claimed_by
      type: string
    - key: disputed_by
      name: disputed_by
      type: string
      from_member: true
    - key: dispute 
      name: dispute 
      type: bool
      from_member: true
    - key: disputed
      name: disputed
      type: bool
      from_member: true
    - key: border_status
      name: border_status
      type: string
      from_member: true
    - key: maritime
      name: maritime
      type: bool
      from_member: true
    - key: boundary_type
      name: boundary_type
      type: string
      from_member: true
    - key: natural
      name: natural
      type: string
      from_member: true
    relation_types: [boundary]
    mapping:
      boundary:
      - administrative
      border_status:
      - dispute
      boundary_type:
      - maritime

  # etldoc: imposm3 -> osm_boundary_polygon
  boundary_polygon:
    type: polygon
    filters:
      require:
        type: [boundary]
        boundary: [aboriginal_lands]
    columns:
    - name: osm_id
      type: id
    - name: geometry
      type: validated_geometry
    - name: name
      key: name
      type: string
    - name: tags
      type: hstore_tags
    - name: boundary
      key: boundary
      type: string
    - name: area
      type: area
    mapping:
      boundary:
      - aboriginal_lands
