From dlc at halibut.com Mon Aug 10 00:48:25 2009 From: dlc at halibut.com (David Carmean) Date: Sun, 9 Aug 2009 21:48:25 -0700 Subject: [Osmlib-user] Detecting closed ways? Message-ID: <20090809214825.C5303@halibut.com> Hi, 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? Thanks. From jochen at remote.org Mon Aug 10 03:15:12 2009 From: jochen at remote.org (Jochen Topf) Date: Mon, 10 Aug 2009 09:15:12 +0200 Subject: [Osmlib-user] Detecting closed ways? In-Reply-To: <20090809214825.C5303@halibut.com> References: <20090809214825.C5303@halibut.com> Message-ID: <20090810071512.GD24832@eldorado.topf.org> 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