Custom OSM way tags


I am using Graphhopper 7 in a java application to perform map matching on an osm file. The map matching part works as expected. The problem is that mapped results do not include way tags that I expect. What I get in the result is an edge ID but for my use case, that is not enough.

An example of a way in the used osm file is:
way id=“236392032” version=“1” timestamp=“” uid=“1” user=“” changeset=“202212011”>
nd ref=“236392065”/>
nd ref=“1000001604127”/>
nd ref=“1000001604128”/>
nd ref=“1000001604129”/>
nd ref=“1000001604130”/>
nd ref=“1000001604131”/>
nd ref=“236392056”/>
tag k=“highway” v=“primary”/>
tag k=“ref” v=“A7”/>
tag k=“oneway” v=“yes”/>
tag k=“official_name” v=“007”/>
tag k=“operator” v=“Overig”/>
tag k=“distance_marker_start” v=“3.982”/>
tag k=“distance_marker_end” v=“3.785”/>

What I need to see, next to edge ID, are the official_name and ref tags.

I get some advice to use TagParsers or EncodedValues, but could not find documentation/examples for using those…

Can someone tell me if this is possible? And how?

Thanks in advance.

There are two things you need here: First you need to make sure the tags you are interested in are considered during the OSM import. Then you need to setup your request such that these details are included in your response.

The “ref” tag is already included by default:

If you want the official_name (not just the name) tag as well I think you need to add similar code that does this.

Note that these tags are a bit special since there are very many possible values for these tags (unlike the highway tag for example), so they aren’t stored as EncodedValues, but rather using the KVStorage.

Do you use map matching via the /match endpoint (http)? If yes, all you need to receive the tags along the matched path is adding using the details parameter:

But note that if you modify the import code to use the official_name you need to add it also here:

to make it work.

1 Like

Hi Easbar,

Thank you for your detailed answer.

The first part, where the OSMReader is modified, looks pretty straightforward.

For the second part, where you mention if I am using the /match endpoint, that is not the case. I am using the map-matching library directly in my app and execute:

MatchResult matchResult = this.mapMatching.match(measurements);
EdgeMatch edgeMatch = matchResult.getEdgeMatches().get(0);

where measurements is a list of Observation(com.graphhopper.util.shapes.GHPoint p )

So here is where i get confunsed again -_-, if I look at the implementation of KVStringDetails then it gets the saved value from the EdgeIteratorState which i can easily access via an EdgeMatch object… is my assumption correct?

Yes, if you are using the Java API it is also easy. You can just repeat the code that runs in MapMatchingResource after the actual map matching:

And yes, at the lowest level you can simply do, e.g.: