Hi,
So far I’ve successfuly implemented spatial rules for ~10 countries. Here are the changes I had to do:
- Create a new
<country-name>SpatialRule.javafile with a class extendingDefaultSpatialRule(as with the german file example:core/src/main/java/com/graphhopper/routing/util/spatialrules/countries/<country-name>SpatialRule.java - Override
getMaxSpeedmethod to set the correct speeds. - Override
getIdto return the 3 letter id of the country or whatever id you are using in your geojson file. - Add a case to the switch in
graphhopper/core/src/main/java/com/graphhopper/routing/util/spatialrules/CountriesSpatialRuleFactory.javawith the country id. - Specify the spatial rule file with the
spatial_rules.locationfield inconfig.yml
Now this will work for some profiles only, see Custom spatial rule with custom vehicule profile.
I wanted to get this to work with other profiles so I ended up creating my own custom profile that kind of merges the DataFlagEncoder with the CarFlagEncoder. This required patches to many files along the way, if you want more details let me know.
Hope this helps