How to avoid blocked areas JAVA

Hello,

I’m trying to set up a server configuration to avoid toll roads and ferries. I’m not using the yml-based configuration.

I checked this post How to avoid area in java but I my question is if I need to add a JSON for the polygon or if there is another way to do this.

My configurations are like this:

Profile profile = new Profile("car");
	profile.setVehicle("car");
	profile.setWeighting("shortest");
	profile.setTurnCosts(true);
	
	CustomModel customModel = new CustomModel()
            .addToPriority(If("toll != NO", MULTIPLY, 0))
            .addToPriority(If("road_environment == FERRY", MULTIPLY, 0))
            .setDistanceInfluence(1000);
	
	CustomProfile customProfileConfig = new CustomProfile(profile);
	customProfileConfig.putHint(CustomModel.KEY, customModel);
	
	List<Profile> profiles = new ArrayList<Profile>(1);
	profiles.add(customProfileConfig);

	GraphHopperConfig config = new GraphHopperConfig()
            .putObject("datareader.file", osmFile)
            .putObject("graph.location", graphFolder)
            .putObject("graph.encoded_values", "road_class,road_class_link,road_environment,max_speed,road_access,toll")
            .setProfiles(profiles)
            .setCHProfiles(Arrays.asList(new CHProfile(customProfileConfig.getName())));
    GraphHopper hopper = new GraphHopper();
    hopper.init(config);
    hopper.importOrLoad();

Thank you in advance for your help,
ML

You can add the corresponding Java objects to the CustomModel instance explicitly, and do not need to use a separate JSON file.

Here is some code where areas are added to a custom model in Java:

Hi easbar,

Thank you for taking the time to assist me. Just one more question, in order to avoid that area I added this:

Map<String, JsonFeature> block = new HashMap<String, JsonFeature>();
	block.put("avoid", area);

CustomModel customModel = new CustomModel()
				.setAreas(block)
				.addToPriority(If("in_avoid", MULTIPLY, 0))
                .addToPriority(If("road_environment == FERRY", MULTIPLY, 0))
                .addToPriority(If("road_environment != FERRY", MULTIPLY, 24 * 60000D))
                .setDistanceInfluence(1000);

But it’s not working as expected. Am I doing something wrong?

Thank you,
ML

Probably latitude and longitude are interchanged. The code I linked to above could be misleading:

 new Coordinate(48.019324184801185, 11.28021240234375)

means the x-coordinate is 48.019 and the y-coordinate is 11.280, so this coordinate is given as lng,lat not lat,lng. So it points to somewhere off the coast near Ethiopia, not Germany…

Thank you very much easbar. It’s working just fine :slight_smile:

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