Aleksander Stankiewicz
Aleksander Stankiewicz

Reputation: 550

Issue with OpenStreetMap administration area rendering

I imported latest OpenStreetMap data to local SQLServer db and generated "outer" shape for some administration area. Original area shape is available here: http://www.openstreetmap.org/relation/2658573

What I received is below:

enter image description here

What I did is I took "outer" way definitions for this shape (mentioned above) in the order defined in the db and constructed POLYGON definition from points belonging to all the ways in the order defined in OpenStreetMap db.

To import data to SQLServer db I used OsmSharp.core nuget package. The orientation of shape data is clockwise as per info on this page(see Naming and Orientation section)): http://wiki.openstreetmap.org/wiki/Talk:Relation:multipolygon

My questions are:

Does anybody know why taking direct definitions for "ways"/lines describing some area shape doesn't work as it should? Should I reject some points from line/way definitions? Maybe I just missed something else...

Edit 1:
I did quick query to verify info from scai and it looks promising:

enter image description here

NodeNr column shows which point on the way/line definition I should take as the start/endpoint for polygon definition. WayNr shows which consecutive way shares point with which one.

Edit 2:
I tested data related to way definitions already and it looks the main issue is with order of nodes in the way definitions only. All the tested ways used all the nodes belonging to them (no any redundant points were there in case the way could cross some other way in the middle of that way).
Some sample data:

enter image description here

The definition of the way with nr 42 (WayNr = 42) shows that start point of this line (continuation of the way nr 41) is on position 44. It means point/node 44 in the definition of the way 42 has the same gps/coordinates as point on position 30 in the definition of way nr 41.

After taking such "reverted" lines in the correct order I received the shape shown below:

enter image description here

After adding an inner area (exclusion) it looks finally as the original one shape:

enter image description here

The other issue with OpenStreetMap data is it uses right-hand rule to define outer-ring of the shape (clockwise instead of counter-clockwise) so in case of SQLServer we have to use ReorientObject() method on Geography instance. To detect orientation of the shape you can use EnvelopeAngle() method on Geography object for instance.

Edit 3:
I received an answer on OSM forum the order of ways on relation members doesn't matter (we can't rely on it) so ways have to be reordered before any further processing yet...

Upvotes: 1

Views: 162

Answers (1)

scai
scai

Reputation: 21469

There are already various similar questions here at stackoverflow and at gis.stackexchange.com.

Relations don't necessarily contain the ways in the correct order. Thus it will be necessary to order the ways yourself. Take a look at the ID of the last node of a way and search for the way who has the same ID for its start node. If you do this for all ways then the resulting geometry should be fine.

Upvotes: 1

Related Questions