You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Missing option to retrieve way id from OSM (OsmReader / DataReader) after updating Graphhopper version #2649
Before, to save map of edgeId to wayId I could use custom DataReader. Now I can see that OsmReader class contains edgeIdToOsmWayIdMap and perfect method addEdge(int fromIndex, int toIndex, PointList pointList, ReaderWay way, Map<String, Object> nodeTags) , but there is no way to override it, because OsmReader is created as local variable in Graphhopper.
Using TagParser wasn't successful either, because library doesn't contain LongEncodedValue, and I wasn't able to write it down myself.
To Reproduce
Upgrade Graphhopper to 5.x version
Expected behavior
Way to override OsmReader or add hook to moment, when edge and way id are written to map. Then we could save it for example in database, and use if to analyze results of MapMatching etc..
Or provide LongEncodedValue, but I think this solution would make graph bigger, and create process would be longer
Using TagParser wasn't successful either, because library doesn't contain LongEncodedValue, and I wasn't able to write it down myself.
At least for the current master this should work: Just add a TagParser that writes to your edgeIdToOsmWayIdMap. Just because it is a tag parser it does not need to store the OSM IDs using an encoded value.
Its hard to tell, because VehicleTagParser doens’t call applyWayTags, so I think, that TagParser itself doesn’t know edge while parsing tag.
Anyway, VehicleTagParser doesn’t exist in the latest release which is 5.3, so its hard for me to test it.
How about keeping osm_way id in IntEncodedValue? Biggest osm_way id is now something around [1088469695]. Int can keep almost twice as much. Then my parser would look something like this:
class OsmWayIdTagParser() : TagParser {
companion object {
val KEY = OsmWayId.KEY
}
private val idValue: IntEncodedValue = OsmWayId.create()
override fun createEncodedValues(lookup: EncodedValueLookup, registerNewEncodedValue: MutableList<EncodedValue>) {
registerNewEncodedValue.add(idValue)
}
override fun handleWayTags(edgeFlags: IntsRef, way: ReaderWay, relationFlags: IntsRef): IntsRef {
idValue.setInt(false, edgeFlags, way.id.toInt())
return edgeFlags
}
}
Is that assumption correct, or there are might be some issues with using Int? Of course it isn't perfect solution, because still it will make my graph creation process longer (and it is long already). But even by using reflection I have no way to hook up to OsmReader, and I can't find any solution of accessing edge id in TagParser
osmParsers.applyWayTags is called afterwards, so that would work in principle. But not sure if this should be the recommended way, because we want to remove this method anyway. We could probably also create the edge first and call the tag parsers afterwards.
How about keeping osm_way id in IntEncodedValue? Biggest osm_way id is now something around [1088469695]. Int can keep almost twice as much.
Yes, works probably, but I did not try.
But even by using reflection I have no way to hook up to OsmReader, and I can't find any solution of accessing edge id in TagParser
You can just fork the code and adjust it as you need.
We should keep this issue in mind and maybe find a better solution to this problem for #1895
Hi, I'm trying to get the way ID too, I need it for purposes related to map matching but I have the impression the situation got worse as edgeIdToOsmWayIdMap got removed.
Are there any solutions/workarounds to get the way ID from OSM right now?
Activity
easbar commentedon Aug 23, 2022
At least for the current master this should work: Just add a TagParser that writes to your
edgeIdToOsmWayIdMap. Just because it is a tag parser it does not need to store the OSM IDs using an encoded value.Coneys commentedon Aug 23, 2022
karussell commentedon Aug 23, 2022
Would the method in VehicleTagParser.applyWayTags work? (question was asked in the forum too)
Coneys commentedon Aug 23, 2022
Its hard to tell, because VehicleTagParser doens’t call applyWayTags, so I think, that TagParser itself doesn’t know edge while parsing tag.
Anyway, VehicleTagParser doesn’t exist in the latest release which is 5.3, so its hard for me to test it.
How about keeping osm_way id in IntEncodedValue? Biggest osm_way id is now something around [1088469695]. Int can keep almost twice as much. Then my parser would look something like this:
Is that assumption correct, or there are might be some issues with using Int? Of course it isn't perfect solution, because still it will make my graph creation process longer (and it is long already). But even by using reflection I have no way to hook up to OsmReader, and I can't find any solution of accessing edge id in TagParser
easbar commentedon Aug 25, 2022
Yes, you're right, the tag parsers are called before the edge is created and the edge ID is assigned. So they cannot access the edge ID:
graphhopper/core/src/main/java/com/graphhopper/reader/osm/OSMReader.java
Lines 335 to 340 in d1ef18c
osmParsers.applyWayTagsis called afterwards, so that would work in principle. But not sure if this should be the recommended way, because we want to remove this method anyway. We could probably also create the edge first and call the tag parsers afterwards.Yes, works probably, but I did not try.
You can just fork the code and adjust it as you need.
We should keep this issue in mind and maybe find a better solution to this problem for #1895
Gabboxl commentedon Nov 28, 2022
Hi, I'm trying to get the way ID too, I need it for purposes related to map matching but I have the impression the situation got worse as
edgeIdToOsmWayIdMapgot removed.Are there any solutions/workarounds to get the way ID from OSM right now?
easbar commentedon Nov 29, 2022
See #2700 and #2701
easbar commentedon Nov 30, 2022
There is now an OSM Way ID encoded value: #2701
Gabboxl commentedon Nov 30, 2022
Thank you for the quick response, works great! Finally!