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
easbar
August 7, 2021, 9:45am
#2
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:
CustomModel customModel = new CustomModel();
Map<String, JsonFeature> areas = new HashMap<>();
Coordinate[] area_1_coordinates = new Coordinate[]{
new Coordinate(48.019324184801185, 11.28021240234375),
new Coordinate(48.019324184801185, 11.53564453125),
new Coordinate(48.11843396091691, 11.53564453125),
new Coordinate(48.11843396091691, 11.28021240234375),
new Coordinate(48.019324184801185, 11.28021240234375),
};
Coordinate[] area_2_coordinates = new Coordinate[]{
new Coordinate(48.15509285476017, 11.53289794921875),
new Coordinate(48.15509285476017, 11.8212890625),
new Coordinate(48.281365151571755, 11.8212890625),
new Coordinate(48.281365151571755, 11.53289794921875),
new Coordinate(48.15509285476017, 11.53289794921875),
};
areas.put("area_1", new JsonFeature("area_1",
"Feature",
null,
new GeometryFactory().createPolygon(area_1_coordinates),
This file has been truncated. show original
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
easbar
August 10, 2021, 9:01am
#4
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…
MLobato
August 10, 2021, 10:22am
#5
Thank you very much easbar. It’s working just fine
system
Closed
November 8, 2021, 10:22am
#6
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.