I have created a new EncodedValue, but when I use this EncodedValue in a Custom model barely any changes to the routing occurs

Hi all,

I have created a new EncodedValue called routing_priority. When I print out the routing_priority for my data, the correct values are displayed and everything seems to be working.

image

However, when I play around with the custom model values and the priority values for each routing_priority, the routes stay the same. Please see the screenshots below of my Config.yml, custom model .json file and a screenshot of the GraphHopper web interface.

Any ideas why the routes don’t change when I change the priority values for my routing_priorities?

Did you create a new FlagEncoder or a new EncodedValue?

I’m not quite sure, but it’s because when you define custom model json file and run the graphhopper with that file, then web interface tweaking became obsolete, that ain’t gonna work. I’ve experienced that sometimes ago. I’m not sure if that is a feature or bug.

I created a new EncodedValue, apologies.

Thanks for your response @rilusmahmud.

In GraphHopper version 4 I am able to define a custom model .json file with certain encoded_values (for example, track_type) and then subsequently tweak that encoded_value in the web interface. See the example below.

This is the route when I define the following priority values for track_type in the config.yml (on the right):

In the web interface, when I change the priority values, notice how the routing changes.

I am only guessing, but this could be related to: https://github.com/graphhopper/graphhopper/issues/2438. Do you start GH using the server command or do you use the Java API. And if you use the Java API how do you register your new encoded value?

Note that you can enable ‘local mvt’ in the layers menu of the web UI to inspect the encoded values for the single edges. You can also add your EV to the PathDetailsBuilderFactory so you can see your encoded value as path detail for debugging.

Thanks for the information @easbar . I am not sure which one of these suggestion I should try. Which one would you recommend? I have added my routing_priority encoded_value to the DefaultTagParserFactory.java and PathDetailsBuilderFactory.java

I start GH using the server command.

For some reason ‘local mvt’ is greyed out by me and I can’t select it.

image

Ok that should work since you are using the server command. So it probably must be something else that goes wrong. To use ‘Local MVT’ you a) need to zoom in far enough and b) set web.mvt.enabled: true in your config.

Thanks for the suggestion for ‘local mvt’. It is working when I zoom in. What is interesting that it is showing only these four encoded_values, even though I have a lot more specified in my config.yml. It is also showing max_speed = infinity. Why would this be the case?

Maybe something is wrong in my routing_priority encoded_value’s code. Would you mind having a look a looks please?

In my data routing_priority is a int ranging from 0 to 4.

RoutingPriority.java:

/*

  • Licensed to GraphHopper GmbH under one or more contributor
  • license agreements. See the NOTICE file distributed with this work for
  • additional information regarding copyright ownership.
  • GraphHopper GmbH licenses this file to you under the Apache License,
  • Version 2.0 (the “License”); you may not use this file except in
  • compliance with the License. You may obtain a copy of the License at
  •   http://www.apache.org/licenses/LICENSE-2.0
    
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an “AS IS” BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.
    */

package com.graphhopper.routing.ev;

public class RoutingPriority {
public static final String KEY = “routing_priority”;

public static IntEncodedValue create() {

    return new UnsignedIntEncodedValue(KEY, 5, true);
}

}

OSMRoutingPriorityParser.java:

/*

  • Licensed to GraphHopper GmbH under one or more contributor
  • license agreements. See the NOTICE file distributed with this work for
  • additional information regarding copyright ownership.
  • GraphHopper GmbH licenses this file to you under the Apache License,
  • Version 2.0 (the “License”); you may not use this file except in
  • compliance with the License. You may obtain a copy of the License at
  •   http://www.apache.org/licenses/LICENSE-2.0
    
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an “AS IS” BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.
    */

package com.graphhopper.routing.util.parsers;

import com.graphhopper.reader.ReaderWay;
import com.graphhopper.routing.ev.EncodedValue;
import com.graphhopper.routing.ev.EncodedValueLookup;
import com.graphhopper.routing.ev.IntEncodedValue;
import com.graphhopper.routing.ev.RoutingPriority;
import com.graphhopper.storage.IntsRef;

import java.util.List;

/**

  • https://wiki.openstreetmap.org/wiki/Key:lanes
    */
    public class OSMRoutingPriorityParser implements TagParser {

    private final IntEncodedValue routing_priorityEnc;

    public OSMRoutingPriorityParser() {
    this.routing_priorityEnc = RoutingPriority.create();
    }

    @Override
    public void createEncodedValues(EncodedValueLookup lookup, List registerNewEncodedValue) {
    registerNewEncodedValue.add(routing_priorityEnc);
    }

    @Override
    public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay way, boolean ferry, IntsRef relationFlags) {
    int routing_priorityCount = 5;
    if (way.hasTag(“routing_priority”)) {
    String noRoutingPriority = way.getTag(“routing_priority”);

     }
     routing_priorityEnc.setInt(false, edgeFlags, routing_priorityCount);
     return edgeFlags;
    

    }
    }

Maybe @rilusmahmud is right. Did you try with an empty custom model server-side (data folder deletion & reimport required) or with an “extreme” value in the custom model (in the UI) e.g. exclude certain edges with routing_priority==0?

1 Like

Hi @karussell

I tried both. See the results below when I test using edges with routing_priority==0.

This is when routing_priority==0 is not excluded and given a high priority.

When I exclude road segments with routing_priority==0, this happens.

It seems that routing_priority is being considered in the route. I suspect that something is not correct in the code above. I will play around with the code and see if something comes right.

Okay, I can see the differences, but maybe there’s a silly quark or feature that got right there in the web interface. In the web interface, you have to maintain the same pattern as the custom model JSON file, and then it works. Otherwise, it remains the same as per the custom mode defined earlier. Then again, as @karussell mentioned earlier, the question remained for data folder deletion & reimport required.

Thanks @rilusmahmud . Let me play around. Hopefully it is something small I am missing

1 Like

I have these encoded_values specified in my config.yml: graph.encoded_values: max_speed,routing_priority,road_class,road_class_link,road_environment,road_access,surface,smoothness,track_type.

Why would the Local MVT only display name, road_environment, max_speed and road_class for my edges?

You can enhance the list of shown encoded values here: graphhopper/web-bundle/src/main/resources/com/graphhopper/maps/js/config/tileLayers.js at b720b6de89c030b728af721705d5eea0a383b821 · graphhopper/graphhopper · GitHub

int routing_priorityCount = 5;

routing_priorityEnc.setInt(false, edgeFlags, routing_priorityCount);

To me it looks as if you are setting all routing_priorityEnc values to hardcoded value 5. Or?

You either need to add details=routing_priority to the url or adjust MvtResource.java, or as ratrun suggested change this in the javascript code.

That worked! Thanks @ratrun

image

Thanks @easbar

I do not want to hardcode all routing_priorityEnc values to 5. Each road segment has each own value ranging from 0 to 4. I want to display and use these routing_priorityEnc values for each road segment. From the screenshot below, it seems I have indeed hardcoded routing_priorityEnc to 5 for all roads :sweat_smile:.

image

Should I remove “int routing_priorityCount = 5”? My java knowledge is very beginner