[Osmlib-user] Detecting closed ways?

Jochen Topf jochen at remote.org
Mon Aug 10 03:15:12 EDT 2009


On Sun, Aug 09, 2009 at 09:48:25PM -0700, David Carmean wrote:
> Have begun trying to use osmexport again, but have not done any ruby for a couple of years.
> I need to detect closed ways so that I can export them as polygons rather than 
> polyines.
> 
> In the rules file, how do I reference the node/way/polygon which being operated on 
> so that I can call is_closed on it?

Its the implicit object.

Just write:

ways do
    if is_closed?
        :polygons << { ... }
    else
        :lines << { ... }
    end
end

Note that is_closed? only checkes whether the ids of the first and last node
are the same. It doesn't do a geometric check so you might end up with
invalid polygons if the way crosses itself.

Jochen
-- 
Jochen Topf  jochen at remote.org  http://www.remote.org/jochen/  +49-721-388298



More information about the Osmlib-user mailing list