Custom spatial rule with custom vehicule profile

I’ve been trying to implement a custom vehicule profile with custom spatial rules.
So far I haven’t managed to do so.

I’m under the impression that this is not currently supported but I haven’t been able to confirm it for sure.

I’ve successfully created and linked my custom vehicule profile based on the car profile. It’s essentially the same thing as the car one except it penalizes speed on a way based on the number of tower nodes of the given way. I can run the service and get results using this profile (mainly the isochrone API).

Now this profile has some country-specific road speeds. I’m working on South Korea and European data at the moment and the road speeds differ from one country to another, so I tried to add a spatial rule for one of the country to try it out.

I’ve tried both the ALT and the CH algorithm without success.

The ALT algorithm uses some geoshapes that are defined in core/src/main/resources/com/graphhopper/routing/lm/map.geo.json which are not the country shapes. I could not find documentation about it in [](the spatial rules doc).
I had to modify certain part of the code to get it “working” as well as use the prepare.lm.split_area_location: core/files/spatialrules/countries.geo.json flag in the configuration about which I haven’t found documentation either.

Now I’m at the point where the service works, but the results I get with and without the spatial rules are identical. I’m under the impression that the DataFlagEncoder is an encoder that is separate from the vehicule encoders and that they cannot be used together.

I was thinking that the spatial rules would override the configuration of my vehicule encoder but it doesn’t seem to work this way.

I’ve been able to use the spatial rules on their own with the generic profile but what I wish for is to use them with my custom profile.

Is that possible or I am trying to do something very wrong and absurd ?

Unfortunately this is all a bit too complicated at the moment. We need to improve this :confused:

With this option you specify how we help the algorithm a bit (performance wise) and cut the assigned area into subregions. Spatial rules are something different.

To implement spatial rules for your custom vehicle you need to store the rule ID in the edge, like we do for the DataFlagEncoder (vehicle=generic) and then modify the speed calculation like this:

1 Like

Thank you for your help @karussell !

Ok I didn’t see it like that. I ran into this option when trying to get the ALT algorithm to use the countries borders in core/src/main/resources/com/graphhopper/routing/lm/map.geo.json
instead of the regions definitions in core/src/main/resources/com/graphhopper/routing/lm/map.geo.json. I thought I needed to use the country file to get the country-based spatial rule working, since the mapping is based on the "ISO_A3" json field.

I’ll try to get it working with this and keep you updated.

Ok so I got something working.
I had to move the spatial rule Logic from DataFlagEncoder to AbstractFlagEncoder but it seems to be working properly, for example for Seoul:

With spatial rules:

Withouth spatial rules:

1 Like