use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class GHResponseTest method testHasNoErrorIfEmpty.
@Test
public void testHasNoErrorIfEmpty() {
assertFalse(new GHResponse().hasErrors());
GHResponse rsp = new GHResponse();
rsp.add(new ResponsePath());
assertFalse(rsp.hasErrors());
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class OSMReaderTest method testRoadClassInfo.
@Test
public void testRoadClassInfo() {
GraphHopper gh = new GraphHopper() {
@Override
protected File _getOSMFile() {
return new File(getClass().getResource(file2).getFile());
}
}.setOSMFile("dummy").setProfiles(new Profile("profile").setVehicle("car").setWeighting("fastest")).setMinNetworkSize(0).setGraphHopperLocation(dir).importOrLoad();
GHResponse response = gh.route(new GHRequest(51.2492152, 9.4317166, 52.133, 9.1).setProfile("profile").setPathDetails(Collections.singletonList(RoadClass.KEY)));
List<PathDetail> list = response.getBest().getPathDetails().get(RoadClass.KEY);
assertEquals(3, list.size());
assertEquals(RoadClass.MOTORWAY.toString(), list.get(0).getValue());
response = gh.route(new GHRequest(51.2492152, 9.4317166, 52.133, 9.1).setProfile("profile").setPathDetails(Collections.singletonList(Toll.KEY)));
Throwable ex = response.getErrors().get(0);
assertTrue(ex.getMessage().contains("You requested the details [toll]"), ex.getMessage());
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class NavigateResponseConverterTest method voiceInstructionTranslationTest.
@Test
public void voiceInstructionTranslationTest() {
GHResponse rsp = hopper.route(new GHRequest(42.554851, 1.536198, 42.510071, 1.548128).setProfile(profile));
ObjectNode json = NavigateResponseConverter.convertFromGHResponse(rsp, trMap, Locale.ENGLISH, distanceConfig);
JsonNode steps = json.get("routes").get(0).get("legs").get(0).get("steps");
JsonNode voiceInstruction = steps.get(14).get("voiceInstructions").get(0);
assertEquals("In 2 kilometers keep right", voiceInstruction.get("announcement").asText());
rsp = hopper.route(new GHRequest(42.554851, 1.536198, 42.510071, 1.548128).setProfile(profile).setLocale(Locale.GERMAN));
DistanceConfig distanceConfigGerman = new DistanceConfig(DistanceUtils.Unit.METRIC, trMap, Locale.GERMAN);
json = NavigateResponseConverter.convertFromGHResponse(rsp, trMap, Locale.GERMAN, distanceConfigGerman);
steps = json.get("routes").get(0).get("legs").get(0).get("steps");
voiceInstruction = steps.get(14).get("voiceInstructions").get(0);
assertEquals("In 2 Kilometern rechts halten", voiceInstruction.get("announcement").asText());
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class NavigateResponseConverterTest method voiceInstructionsTest.
@Test
public void voiceInstructionsTest() {
GHResponse rsp = hopper.route(new GHRequest(42.554851, 1.536198, 42.510071, 1.548128).setProfile(profile));
ObjectNode json = NavigateResponseConverter.convertFromGHResponse(rsp, trMap, Locale.ENGLISH, distanceConfig);
JsonNode steps = json.get("routes").get(0).get("legs").get(0).get("steps");
// Step 4 is about 240m long
JsonNode step = steps.get(4);
JsonNode voiceInstructions = step.get("voiceInstructions");
assertEquals(2, voiceInstructions.size());
JsonNode voiceInstruction = voiceInstructions.get(0);
assertEquals(200, voiceInstruction.get("distanceAlongGeometry").asDouble(), 1);
assertEquals("In 200 meters At roundabout, take exit 2 onto CS-340, then At roundabout, take exit 2 onto CG-3", voiceInstruction.get("announcement").asText());
// Step 14 is over 3km long
step = steps.get(14);
voiceInstructions = step.get("voiceInstructions");
assertEquals(4, voiceInstructions.size());
voiceInstruction = voiceInstructions.get(0);
assertEquals(2000, voiceInstruction.get("distanceAlongGeometry").asDouble(), 1);
assertEquals("In 2 kilometers keep right", voiceInstruction.get("announcement").asText());
voiceInstruction = voiceInstructions.get(3);
assertEquals("keep right", voiceInstruction.get("announcement").asText());
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class NavigateResponseConverterTest method testMultipleWaypoints.
@Test
public void testMultipleWaypoints() {
GHRequest request = new GHRequest();
request.addPoint(new GHPoint(42.504606, 1.522438));
request.addPoint(new GHPoint(42.504776, 1.527209));
request.addPoint(new GHPoint(42.505144, 1.526113));
request.addPoint(new GHPoint(42.50529, 1.527218));
request.setProfile(profile);
GHResponse rsp = hopper.route(request);
ObjectNode json = NavigateResponseConverter.convertFromGHResponse(rsp, trMap, Locale.ENGLISH, distanceConfig);
// Check that all waypoints are there and in the right order
JsonNode waypointsJson = json.get("waypoints");
assertEquals(4, waypointsJson.size());
JsonNode waypointLoc = waypointsJson.get(0).get("location");
assertEquals(1.522438, waypointLoc.get(0).asDouble(), .00001);
waypointLoc = waypointsJson.get(1).get("location");
assertEquals(1.527209, waypointLoc.get(0).asDouble(), .00001);
waypointLoc = waypointsJson.get(2).get("location");
assertEquals(1.526113, waypointLoc.get(0).asDouble(), .00001);
waypointLoc = waypointsJson.get(3).get("location");
assertEquals(1.527218, waypointLoc.get(0).asDouble(), .00001);
// Check that there are 3 legs
JsonNode route = json.get("routes").get(0);
JsonNode legs = route.get("legs");
assertEquals(3, legs.size());
double duration = 0;
double distance = 0;
for (int i = 0; i < 3; i++) {
JsonNode leg = legs.get(i);
duration += leg.get("duration").asDouble();
distance += leg.get("distance").asDouble();
JsonNode steps = leg.get("steps");
JsonNode step = steps.get(0);
JsonNode maneuver = step.get("maneuver");
assertEquals("depart", maneuver.get("type").asText());
maneuver = steps.get(steps.size() - 1).get("maneuver");
assertEquals("arrive", maneuver.get("type").asText());
}
// Check if the duration and distance of the legs sum up to the overall route distance and duration
assertEquals(route.get("duration").asDouble(), duration, 1);
assertEquals(route.get("distance").asDouble(), distance, 1);
}
Aggregations