osmcode/node-osmium

Area callback not always called

Closed this issue · 2 comments

I'm trying to get areas from an OSM extract, and have encountered some inconsistent results that I have a hard time explaining even after having a long look at both the node-osmium and libosmium code.

My test code is here: https://gist.github.com/perliedman/8aca70d2a12f00dbac15

When running the code against the provided extract, I get 25 vertices, 3 ways and 0 areas. I was expecting the ways to be turned into areas, since they are closed (I've verified that they look ok in JOSM).

The weird thing is that if I run a larger extract of the same area (a bit too large to post in the gist), one of these two ways end up as an area, while the other does not. In fact, about half of the closed ways in this larger extract are turned into areas, while the other are dropped.

To debug this, I've enabled debug mode in libosmium's AssemblerConfig, but the logs look the same for ways that are turned into areas as well as ways that are not turned into areas.

All of this is with node-osmium and libosmium code that I cloned earlier today.

joto commented

Okay, this was a complicated one. The problem was that buffers were not flushed properly in all cases. That's why you saw some areas when trying with the larger extracts. Those areas were handled first and written out the rest didn't make it. In your small example non of them were flushed.

Unfortunately there is no easy fix without changing user code, you have to add some end() calls to the handlers. See here for an example:
https://github.com/osmcode/node-osmium/blob/master/demo/multipolygon/index.js

You also might want to check out the FlexReader() it makes Area-Handling simpler, hiding some of the boiler-plate code. The example file I mentioned has both versions in it.

Thanks a lot, works very well!