What profile to use with custom models

Hi, I’m connecting to graphhopper using the java client located here
implementation ‘com.graphhopper:directions-api-client-hc:5.3’

I’m trying to use polygon-based vehicle profiles as described here

I’ve built a CustomModel and I’m passing it in to request.setCustomModel, but I’m getting an error telling me I have to set the profile. Is there a special token that means “go use the custom model”? Or do I somehow associate a name with the model?
When I was routing client side, I could associate it by building a CustomProfile, but I don’t seem to have access to that class in the client library.

Please advise

Yes, every custom model is based on some profile. Currently, you can use car,small_truck,scooter,foot or bike. For example if you use profile: car and setup a rule in your custom model that does multiply_by: 0.8 for speed, 80% of the normal car speed will be used for the affected roads.

Okay, thanks.

So if I set it to “car” I get the following error:
“The requested profile ‘car’ cannot be used with custom_model, because it has weighting=fastest”

Do I have to do something to override the default weighting of “car”?

This is my profile btw, which is copied straight off the examples link

“priority”: [{
“if”: “road_class == MOTORWAY && in_near_cottbus == false”,
“multiply_by”: 0
“areas”: {
“near_cottbus”: {
“type”: “Feature”,
“properties”: {},
“geometry”: {
“type”: “Polygon”,
“coordinates”: [[
[ 13.84826, 51.6137 ],
[ 13.9746, 51.61375 ],
[ 13.97323, 51.82983 ],
[ 13.84963, 51.83323 ],
[ 13.84826, 51.6137 ]

This is your custom model. What does your request look like? And are you querying against graphhopper.com/api/1/route or do you run your own GraphHopper server?

I’m running my own server (it’s 4.0 with no changes). My request looks like this (I’m using the java client)

GHRequest request = new GHRequest(start.getLatitude(), start.getLongitude(),
end.getLatitude(), end.getLongitude());
request.putHint(“instructions”, false);
request.putHint(“ch.disable”, true);

To use custom models you need to set up at least one custom profile. In your config.yml file:

  - name: abc
    weighting: custom
    vehicle: car
    custom_model_file: empty

And then use profile=abc in your request. This is all written here. Did you not read this or was it not clear?

1 Like

Yes, that is quite clear, thank you.

I read several guides, but apparently I didn’t read that one to the end.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.