We are using osm2pgsql to import the OpenStreetMap's planet.osm file to GeoServer. Then we try to get features from the polygon layer using GDAL/OGR's WFS driver in C#.

We've tried the import with and without the --multi-geometry option.

The multi-polygon I'm using for testing is http://www.openstreetmap.org/relation/69663. I try to fetch the relevant features with
layer.SetAttributeFilter("(osm_id=69663)OR(osm_id=28414267)OR(osm_id=30407439)"); The above ID's are the relation ID of the multi-polygon, the way ID of the outer way and the way ID of the inner way, respectively. This query returns only a single feature with a single geometry with 22 nodes and no nested geometries. This feature matches the outer way in ID, number of nodes and its tags. This means that not only is it missing the inner way; it is also missing the tags from the relations, which is what identifies it as a building.

What happened with the inner way? Was it discarded because it doesn't have any tags? What happened with the relation? Most importantly, how do I get the result I seek?

EDIT: iant wanted to know what was in the geometry column. The geometry column is named "way" and for the osm_id 28414267 it contains:
We converted it to text and it contains exactly what I got with OGR: 22 nodes, no nested geometries.

EDIT 2: The above hexadecimal data as text:
POLYGON((13.0033859 55.6034478,13.0033895 55.6034879,13.0034498 55.6035139,13.0034888 55.603522,13.0038763 55.6035696,13.0039767 55.603582,13.0043688 55.6036302,13.0044043 55.6036322,13.004454 55.6036182,13.0044791 55.6036046,13.0045036 55.6035841,13.0046976 55.603071,13.0047272 55.6029928,13.0047165 55.6029707,13.0046633 55.6029467,13.0038259 55.6026179,13.003762 55.6026179,13.0037124 55.6026259,13.0036769 55.6026781,13.0034473 55.6032854,13.0034328 55.6033237,13.0033859 55.6034478))
I'm too lazy to check all of them, but the eleventh node (13.0045036 55.6035841) matched the first node on OpenStreetMap.

  • what is in the geometry column in PostGIS for that ID?
    – Ian Turton
    Feb 14, 2017 at 9:57
  • The content does not fit in a comment, so I added it to the question.
    – Kapten-N
    Feb 14, 2017 at 10:44
  • That's ok you're supposed to edit your question to clarify. Now we really need to see the WKT not the WKB of your way so please run ST_AsText on the way value and paste that in instead
    – Ian Turton
    Feb 14, 2017 at 10:51
  • I've done as you asked now. The coordinates seem to match the outer way, though I only checked one of them. My colleague claims that it would say MULTIPOLYGON instead of just POLYGON if it was one.
    – Kapten-N
    Feb 14, 2017 at 11:31
  • looks like there is an issue with the input data /osm2psql - you should get a POLYGON with a hole so POLYGON((.....),(..Hole Coords...))
    – Ian Turton
    Feb 14, 2017 at 11:40

1 Answer 1


After importing a very small area with less than 20 objects I've found the problem!

To prevent overlap between relation IDs and way IDs relations are imported with a negative ID number.

I have not found this fact documented anywhere. I found out because I recognized the ID I was looking for in the database because I imported such a small area.

What I should have written from the start was layer.SetAttributeFilter("(osm_id=-69663)");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.