omniscale/imposm3

Missing and empty polygons after import (related to building and parts)

Closed this issue · 6 comments

Context

I'm trying to import buildings/polygons from OSM, some of them are defining multi part buildings (with parts of different heights/levels).

I tried to import the data using polygon and geometry mappings, they both fail with different behaviors:

  • The geometry mapping will import the data with a POLYGON EMPTY geometry
  • The polygon mapping will ignore the data

My example is relation/13155725, you can get download the gzipped data from direct dowload relation-13155725.osm.pbf.gz and relation-13155725.osm.xml.gz or get the XML from overpass using this query:

[out:xml][timeout:25];
rel(13155725)({{bbox}});
(._;>;);
out;

I did some experiments (removing some parts) and it seems that the member of a relation type=building with the role=part is considered as a inner hole of a multi polygon. Since in this example the union of all parts equals the outline, the polygon disappear, that's why the result is POLYGON EMPTY.

I need both of the geometries for their tags and sometime relations have more information than outlines.

Expected Behavior

When getting data for both tables osm_test_buildings_geom and osm_test_buildings_poly, the geometry should be (at least) the outline polygon.

postgres=# select osm_id, ST_AsText(geometry)  from osm_test_buildings_geom where osm_id = -13155725;
  osm_id   |             st_astext
-----------+---------------------------------
 -13155725 | POLYGON((976945.8716064208....))

Actual Behavior

postgres=# select osm_id, ST_AsText(geometry)  from osm_test_buildings_geom where osm_id = -13155725;
  osm_id   |   st_astext   
-----------+---------------
 -13155725 | POLYGON EMPTY

Possible Fix

Filter role=parts members when creating buildings. This will result to have two polygons, the outline (if the tag building=* is present) and the relation.

A workaround for those passing by is using a relation mapping and doing an SQL JOIN.

Steps to Reproduce

Mapping configuration:

tags:
  load_all: true
tables:
  test_buildings_poly:
    fields:
    - name: osm_id
      type: id
    - name: geometry
      type: geometry
    - name: tags
      type: hstore_tags
    mapping:
      building:
      - __any__
    type: polygon
  test_buildings_geom:
    fields:
    - name: osm_id
      type: id
    - name: geometry
      type: geometry
    - name: tags
      type: hstore_tags
    type_mappings:
      polygons:
        building:
        - __any__
    type: geometry
  1. Download relation-13155725.osm.pbf.gz
  2. import with the above configuration
  3. The table osm_test_buildings_geom should have 2 geometries, way/978521649 with the correct geometry and relation/13155725 with an empty polygon
  4. The table osm_test_buildings_poly should have 1 geometry, way/978521649 with the correct geometry

Your Environment

  • Version used: Imposm3 v0.12.0
  • Environment name and version: PostgreSQL 11 with PostGIS 3.3
  • Server type and version: Docker 26.1.1
  • Operating System and version: Postgres under Alpine Linux & Imposm3 under Debian Bookworm
olt commented

Imposm inserts the geometry as 978521649 and not -13155725. Imposm always inserts a geometry only once for the same mapped tags (building=any in this case). The outer way should not have a building=yes tag if the metadata is on the relation: https://wiki.openstreetmap.org/wiki/Relation:multipolygon

Hello, thank you for your fast response, unfortunately, when I remove the tag building=yes on 978521649, the behavior is still the same and not the one you're describing, in that case 978521649 is no longer imported and:

  • osm_test_buildings_poly is now an empty table
  • osm_test_buildings_geom contains only -13155725 as POLYGON EMPTY

Again, this is not a multipolygon relation but a 3D building relation (with building parts): https://wiki.openstreetmap.org/wiki/Relation:building#For_3D_modelling

This relation is wrongly processed as multi polygon, that's why I have a POLYGON EMPTY as a result, all the parts are considered as holes, making the whole polygon disappearing.

olt commented

all the parts are considered as holes, making the whole polygon disappearing.

Right.

The examples in the linked wikipage shows that the tags should be on the outer way and the relation should just contain type=building.

The examples in the linked wikipage shows that the tags should be on the outer way and the relation should just contain type=building.

Yes, the general consensus with Simple 3D Building relations is that the tags related to the entire building should be on the relation member with role=outline, not on the type=building relation definition, as is the case in this example. Putting the data on the member with role=outline makes it far more easy for data consumers to process the building data in OpenStreetMap, as they are not forced to process every single type=building relation, but can rely on simpler processing of ways only for building data (which will include the ones with role=outline).

Yes ok I understand, but why am I getting empty geometries ?... Is it a normal behaviour ?...

I just found out that the geometry mapping is also producing POLYGON EMPTY on some relation such as relation/12240295
So this may not be linked to building after all.