[OSM-dev] osm2spatialite!

Daniel Sabo danielsabo at gmail.com
Thu Feb 17 09:23:29 GMT 2011


On Feb 16, 2011, at 11:58 PM, Frederik Ramm wrote:

> Daniel,
> 
> On 02/17/11 02:57, Daniel Sabo wrote:
>> I did find a version of spatialite that supported build area after I
>> had written the multipolygon code, but I've decided to keep the code
>> in osm2spatialite because it does a much better job of generating
>> valid multipolygons that BuildArea can (because BuildArea doesn't
>> have a concept of the inner and outer roles).
> 
> Can you elaborate on how having "inner" and "outer" roles helps one in building a valid geometry?

So, this does assume that it started as a valid OSM multipolygon, if it fails that requirement I think we're better of fixing it in OSM than coding around it :).

A valid Simple Feature polygon needs to have a non-self-intersecting / non-self-touching outer ring, but inner rings are allowed to touch outer rings. When you look at an inner line that shares an endpoint with an outer line and ignore roles there's a 50/50 chance of appending it to the wrong ring. About 3/4 of the really complex multipolygons I look at in the osm2pgsql database end up with self intersections like this, considering the roles gets it down to 1/4 (because I still may screw up when they're are two outer rings that share a node).

I do ignore the roles after the rings are built, so if there's an outer immediately inside another outer it will just consider the 2nd one an inner.

An even more optimal algorithm would probably be to try to backtrack when you create a self intersection, or walk through the nodes in the rings you've built and split them if a node is used twice. But so far that's fallen into "it renders so I won't worry about it for now".

Also, I think this issue gets hidden because a fair number of the theoretically valid multipolygons get tweaked until osm2pgsql can handle them. I know it took me several tries when adding the Oregon national forest boundaries to adjust them so inner ways didn't shared endpoints with outer ways. But it wasn't until I wrote osm2spatialite that I actually understood WHY they wouldn't render.

- Daniel

> Reason I'm asking is that in all the code where *I* generate geometries from multipolygon relations, I explicitly ignore the role because using the role would actually lead to more, not less, invalid multipolygons.
> 
> Bye
> Frederik
> 
> 
> _______________________________________________
> dev mailing list
> dev at openstreetmap.org
> http://lists.openstreetmap.org/listinfo/dev




More information about the dev mailing list