Find out in which country a way is located

Hi all of you,

I have another question about graphhopper. We switch our graph from germany to europe. But our toll implementation is only for germany and shouldn’t be used in other countries. (from geofabrik)

If I understand it the right way, I have to move my toll implementation to a spatial rule(for ex. GermanySpacialrule) and just implement a spacial rule lookup/extending the interface to my needs.

Am I correct? And do you have any downsides of this? I see you are using the estimated_center tag from a way. Do you have any bad experience with that? For example are there many ways which don’t use that tag at all?(Example wayId: 25950405) Also where do the specified file and bbox go to? (where is it read, just couldn’t find it in the classes. (I’m on 0.9.0)

Another thing I saw is a nominatim osm service with reverse geocoding to get a lat,long for a wayID. But it involves more work and some server to run the service. Any experiences with that?

Thanks in advance and best wishes,
Martin

Internally we had a similar requirement and used spatial rules. As our requirements were a bit more special we extended ChangeGraphHelper with spatial rules support, see issue Unify bulk customization of graph properties like speed and access · Issue #1280 · graphhopper/graphhopper · GitHub and this was applicable to other FlagEncoders not just the DataFlagEncoder.

To use the default behaviour you specify a JSON at spatial_rules.location and it should set the SpatialRuleLookup for the DataFlagEncoder. See GraphHopperModule in 0.9 branch.

Do you have any bad experience with that? For example are there many ways which don’t use that tag at all?

It is a virtual tag that we introduce in OSMReader, so all ways should have it.

Another thing I saw is a nominatim osm service with reverse geocoding to get a lat,long for a wayID. But it involves more work and some server to run the service. Any experiences with that?

I would not do this (slow and requires wayID in GH). Instead you could consider using the German border to mark border edges (using LocationIndexTree), we did so for yet another use case where we wanted to disconnect countries from each other. This works very similar to the code in LandmarkStorage.findBorderEdgeIds but in your case you just “mark” those edges and then e.g. floodfill the graph with actual toll information until the border edges are reached starting from any node inside Germany.

1 Like

Sorry for the late answer, but I wasn’t able to come to this problem until now. I looked into the GraphhopperModule and implemented the principle of the DataFlagEncoder into my own encoder. Thanks again for the help. :slight_smile: