How to block certain edge with AvoidEdgesWeighting

Hello all
I am trying to use this awesome package. I am using this on IntelliJIDEA. I ran it smoothly there. I now need to block certain edges. I know the actual osm-way-id of the edges. e.g., the Osm_id/Osm-way-id for I-270 in Maryland is 382296939. I hope to use this code https://github.com/graphhopper/graphhopper/blob/94ac7f853f3a9053cfb7e202ca020b03e425e783/core/src/main/java/com/graphhopper/routing/weighting/AvoidEdgesWeighting.java#L50 for that.

However, I actually do not know Java and thus still trying to figure out how to use that. How and where to specify that edge to avoid and how to use that code? Is there any sample code showing the usage within the main GraphHopper file? I know it might be very novice question but I am very grateful for any suggestion.

Thanks

Hi,

I’m new to GH but I know Java. I dont know if you can directly block one OSM_Way_ID or OSM_Rel_ID but I know a work-arround.

If your restricted edge hasa unique Tag than you can wirte your own FlagEncoder and add this tag to restrictedValues.

If the edge you want to blog has commen Tags with other edges you don’t want to block I wolud add a new own unique Tag to the OSM Object you want to block (Please don’t upload this temp Tag to OSM).

Than you can write a new Encoder and add your own Tag to the list of restrictedValues.

 class MyEncoder extends CarFlagEncoder{

    MyEncoder(){
        super();
            this.restrictedValues.add("MyRestrictedOSMTag");
    }
}

//And than
hopper = new GraphHopperOSM().forServer();
hopper.setDataReaderFile(osmPath);
hopper.setGraphHopperLocation(StorePath);
hopper.setEncodingManager( EncodingManager.create(new MyEncoder()));
hopper.importOrLoad();

This might be a hacky way but should work.
Here is a link on how to wire your own encoder.

Hope this helps

2 Likes

As someone who has been working a project (trying to block certain edges), I feel it should be make explicitly clear - To my understanding “OSM Way IDs” and “OSM Edges” are two different things. OSM Ways are arbitrary-length roads/lines that are uniquely identified with an OSM ID and various tags. “OSM Edges” are the sub-segments shorter-lengths, which make up of various intersecting OSM Ways.

Correct me if I’m wrong but the above solution by @Henne sounds like a solution for working with OSM Way IDs.

I have to admit I didn’t understand the question well enough to be sure @subrina0013 was talking about GH edges which sure may be smaller than OSM ways. But OJ often reffers to OSM_ids which can be blocked by setting an unique Tag and adding ths tag to the restrictedValues.

@Dylansc your are right this solution would only work with osm-ways. If @subrina0013 wants to remove speciftc edges in GH than he has to figure ot a way to map the osm-ways he knows to the GH edges he wasts to block

Thank you so much for your responses. Actually, I used https://github.com/karussell/graphhopper-osm-id-mapping to get the actual unique ‘OSm-way ids’ for the ‘OSM Edges’. So, I know both the ids for each edge of the graph.
So, do you think I can use ‘OSM Edges’ as my tag?

I use a new class that has the following update. added a list of way-ids that need to be blocked.

public class CarExpFlagEncoder extends AbstractFlagEncoder {
…
long blocked = new long{};
if (LongStream.of(blocked).anyMatch(x → x == way.getId())) {
return EncodingManager.Access.CAN_SKIP;
}

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