Skip to content

Missing option to retrieve way id from OSM (OsmReader / DataReader) after updating Graphhopper version #2649

Closed

Description

@Coneys

Describe the bug

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

Activity

  1. easbar commented on Aug 23, 2022

    @easbar
    Member

    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.

  2. Coneys commented on Aug 23, 2022

    @Coneys
    Author
  3. karussell commented on Aug 23, 2022

    @karussell
    Member

    Would the method in VehicleTagParser.applyWayTags work? (question was asked in the forum too)

  4. Coneys commented on Aug 23, 2022

    @Coneys
    Author

    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

  5. easbar commented on Aug 25, 2022

    @easbar
    Member

    Sure, that was my first idea, but TagParser doesn't provide easy access to edge id,only edge flags. Any ideas how to get edge id in tag parser?

    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:

    IntsRef edgeFlags = encodingManager.createEdgeFlags();
    edgeFlags = osmParsers.handleWayTags(edgeFlags, way, relationFlags);
    if (edgeFlags.isEmpty())
    return;
    EdgeIteratorState edge = baseGraph.edge(fromIndex, toIndex).setDistance(distance).setFlags(edgeFlags);

    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

  6. Gabboxl commented on Nov 28, 2022

    @Gabboxl

    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?

  7. easbar commented on Nov 29, 2022

    @easbar
    Member

    See #2700 and #2701

  8. easbar commented on Nov 30, 2022

    @easbar
    Member

    There is now an OSM Way ID encoded value: #2701

  9. Gabboxl commented on Nov 30, 2022

    @Gabboxl

    See #2700 and #2701

    There is now an OSM Way ID encoded value: #2701

    Thank you for the quick response, works great! Finally!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions