How to add a new encoded value

Hi,

On my car.json profile i want a new value “Timeband” how can i read this value out of the .json so its useable in the code?

car.json

{
“distance_influence”: 15,
“time_band”: “w1”,
“priority”: [
{
“if”: “road_access==DESTINATION||road_access==PRIVATE”,
“multiply_by”: “0.1”
},
{
“if”: “road_class==SERVICE||road_class==TRACK”,
“multiply_by”: “0.5”
}

],
“speed”: [
{
“if”: “true”,
“limit_to”: “car_average_speed”
}
]
}

graph.encoded_values: car_access, car_average_speed, road_access, road_class, time_band

Error:

Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field “time_band” (class com.graphhopper.util.CustomModel), not marked as ignorable (5 known properties: “distance_influence”, “heading_penalty”, “areas”, “speed”, “priority”])

Thanks,
Brandon

This is rather complex and you’ll need to modify the CustomModel class and also the CustomWeighting and/or CustomWeightingParser to consider it.

It is recommended that you use it directly speed and priority statements as encoded value.

Hi,

Do you have an example of how i can use my new “time_band” directly in the priority/speed array, encoded value?

My end goal is that i can define the time_band in the profile, and at the Weighting level have this data to influence which weighting value i use.

To note, there is no road data which is called “time_band” its a made up name just for the sake of identification and doesn’t related to any road segments, etc.

“priority”: [
{ “if” : “time_band == 1”, “multiply_by”: “0”
]

Thanks,
Brandon

Just add it to the profile, not the custom_model. Then it will be available in com.graphhopper.config.Profile#getHints().

1 Like

Hi,

Thanks for the reply, bit of confusion.

How do i access my profile name/hints in the Weighting class.

So i just add it below name: to be directly in the profile and not the custom_model?

Thanks,
Brandon

Take a look at DefaultWeightingFactory.java where the CustomWeighting object is created. At this point you will have access to the profile (and hints). But you will need to pass it on to your weighting class.

Yes, this way it will be available in the profile.