Repository navigation
OSMReader has problems with ways that reference missing nodes - #2221
Conversation
|
This PR now fixes the issue: When there are ways that start/end with references to non-existing nodes the missing nodes are ignored. I also added two checks that run during the import and make sure that the edge distance always matches the edge geometry and the coordinates of the first/last points in the temporary pointList match those of the tower nodes. The first check is now possible because of #2222. |
| int lastExisting = -1; | ||
| for (int i = 0; i < osmNodeIds.size(); ++i) { | ||
| final long tmpNode = getNodeMap().get(osmNodeIds.get(i)); | ||
| if (tmpNode > -TOWER_NODE || tmpNode < TOWER_NODE) { |
There was a problem hiding this comment.
Btw one of the major difficulties I had when trying to understand OSMReader is that the node map is used in two different ways during the import. In the first pass it simply separates between nodes that occur in two or more, only one or zero ways. For this we use the TOWER/PILLAR/EMPTY_NODE constants. But then in the second run we use the same map and assign pillar/tower node ids and this leads to very confusing code like this:
// skip osmIds with no associated pillar or tower id (e.g. !OSMReader.isBounds)
if (tmpNode == TOWER_NODE)
continue;
if (tmpNode == PILLAR_NODE) {where tmpNode == TOWER/PILLAR_NODE does not mean that tmpNode is a tower/pillar node but it means something very different(!): Because no 'real' tower/pillar node id was assigned for this node it means that tmpNode does not exist.
This is probably the first thing I would clean up in OSMReader, because it really tripped me up. I understand that we probably want to re-use the map for performance reasons, but at least we should use a second reference to it (using a different name) or use some helper methods to make this more clear. Then again I wonder if we could exploit the fact that during the first pass we only need to distinguish three values (zero ways, one way, multiple ways) to achieve faster lookups somehow.
There was a problem hiding this comment.
if we could exploit the fact that during the first pass we only need to distinguish three values
For example we could use a LongHashSet to store all OSM node Ids that occur in any way and a second (smaller) one to keep track which of these nodes are tower nodes. Not sure if this would be an improvement, because before pass2 we would still have to build the mapping between OSM node Ids and GH tower/pillar IDs.
There was a problem hiding this comment.
but at least we should use a second reference to it (using a different name) or use some helper methods to make this more clear.
👍
For example we could use a LongHashSet to store all OSM node Ids that occur in any way
The problem might be for big maps with millions of nodes as sets behave very ugly then: when increasing the size you double the size (additionally to the load factor of usually 0.75) and so you will need 3*1/0.75 = 4 and then you need to copy such big arrays.
But surely we can just try as the memory usage requirements changed significantly over the last years. Still at some point not too far in the past I tried with a database like mapdb but it was still much slower and used more resources (disk+memory).
There was a problem hiding this comment.
Ok yes this was just an idea, its probably hard to say without trying it. Also I am not even sure if there is really much need to speed up the OSM parsing and improving readability seems more important.
There was a problem hiding this comment.
Yes, a speed up is not necessary. Still I would like it, if the new version is not much slower :) (maybe max 2x slower? probably depends on the gained readability)
| // #2221: ways might include nodes at the beginning or end that do not exist -> skip them | ||
| int firstExisting = -1; | ||
| int lastExisting = -1; |
There was a problem hiding this comment.
The actual fix is a bit lengthy, but rather trivial: We scan the osmNodeIds list from the beginning and end to find the first node that does exist (and skip those that do not exist).
This still seems like a good solution to the problem to me, but I am not sure if these data errors occur in e.g. Geofabrik extracts. Also some of our testing maps contain these kind of errors so we would have to replace them as well. For now I think we should apply the fix (and maybe consider this again when fixing #2220, #2223 etc.) |
There was a problem hiding this comment.
Sometimes OSM ways reference nodes that do not exist in the OSM file.
The assumption before was that this will never happen (in geofabrik PBFs this did not occur to my knowledge). But is nice that we know and partially fix this now when it happens.
Also some of our testing maps contain these kind of errors
Interesting. Whenever I created a test PBF I used the export feature of openstreetmap.org and if it is a pbf converted the xml to a pbf with probably osmosis. So maybe the most tools are not 100% strict.
We actually already handled a similar case before, see #19. But this was only for missing nodes in the middle of a way. The worst part was that we did not throw an error in case some nodes were missing unexpectedly. |
Sometimes OSM ways reference nodes that do not exist in the OSM file. This problem was partly fixed in #19 (yes long ago), but only for the case where the missing nodes where somewhere in the middle of a way. However, when the missing nodes are at the beginning of the way I ran into two problems:
edge.getDistance() != calcDistance(edge.fetchWayGeometry(FetchMode.ALL)).Such missing nodes appear frequently when we extract a box using Osmosis. In this case often the first or last nodes are missing, because the way starts/ends outside of the bounding box. See #1984. I am not sure if this can also happen with original OSM files.
If this data issue only arises when using certain tools like Osmosis I think we should simply reject such data. Its easy to throw an appropriate error in this case and It should be easy enough use some tool to fix the issue before importing it with GH. In this case maybe we can also get rid of the code that was added for #19. Otherwise we would need to add some code that handles this situation correctly. Even leaving out such ways entirely would be an option IMO, but there should definitely be no edges with inconsistent distances, because this leads to problems like #1984.