use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.
the class GraphHopperIT method checkMultiVehiclesWithCH.
private void checkMultiVehiclesWithCH(GraphHopper tmpHopper) {
String str = tmpHopper.getEncodingManager().toString();
GHResponse rsp = tmpHopper.route(new GHRequest(43.73005, 7.415707, 43.741522, 7.42826).setVehicle("car"));
PathWrapper arsp = rsp.getBest();
assertFalse("car routing for " + str + " should not have errors:" + rsp.getErrors(), rsp.hasErrors());
assertEquals(207, arsp.getTime() / 1000f, 1);
assertEquals(2838, arsp.getDistance(), 1);
rsp = tmpHopper.route(new GHRequest(43.73005, 7.415707, 43.741522, 7.42826).setVehicle("bike"));
arsp = rsp.getBest();
assertFalse("bike routing for " + str + " should not have errors:" + rsp.getErrors(), rsp.hasErrors());
assertEquals(494, arsp.getTime() / 1000f, 1);
assertEquals(2192, arsp.getDistance(), 1);
rsp = tmpHopper.route(new GHRequest(43.73005, 7.415707, 43.741522, 7.42826).setVehicle("foot"));
assertTrue("only bike and car were imported. foot request should fail", rsp.hasErrors());
GHRequest req = new GHRequest().addPoint(new GHPoint(43.741069, 7.426854), 0.).addPoint(new GHPoint(43.744445, 7.429483), 190.).setVehicle("bike").setWeighting("fastest");
rsp = hopper.route(req);
assertTrue("heading not allowed for CH enabled graph", rsp.hasErrors());
}
use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.
the class GraphHopperIT method testMonacoNonChMaxWaypointDistanceMultiplePoints.
@Test
public void testMonacoNonChMaxWaypointDistanceMultiplePoints() {
GHPoint from = new GHPoint(43.741069, 7.426854);
GHPoint via = new GHPoint(43.744445, 7.429483);
GHPoint to = new GHPoint(43.727697, 7.419199);
GHRequest req = new GHRequest().addPoint(from).addPoint(via).addPoint(to).setVehicle(vehicle).setWeighting("fastest");
// Fail since points are too far
hopper.setNonChMaxWaypointDistance(1000);
GHResponse rsp = hopper.route(req);
assertTrue(rsp.hasErrors());
PointDistanceExceededException exception = (PointDistanceExceededException) rsp.getErrors().get(0);
assertEquals(2, exception.getDetails().get("to"));
// Suceed since points are not far anymore
hopper.setNonChMaxWaypointDistance(Integer.MAX_VALUE);
rsp = hopper.route(req);
assertFalse(rsp.hasErrors());
}
use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testVia.
@Test
public void testVia() {
instance = new GraphHopperOSM().setStoreOnFlush(true).init(new CmdArgs().put("datareader.file", testOsm3).put("prepare.min_network_size", "1").put("graph.flag_encoders", "car")).setGraphHopperLocation(ghLoc);
instance.importOrLoad();
// A -> B -> C
GHPoint first = new GHPoint(11.1, 50);
GHPoint second = new GHPoint(12, 51);
GHPoint third = new GHPoint(11.2, 51.9);
GHResponse rsp12 = instance.route(new GHRequest().addPoint(first).addPoint(second));
assertFalse("should find 1->2", rsp12.hasErrors());
assertEquals(147930.5, rsp12.getBest().getDistance(), .1);
GHResponse rsp23 = instance.route(new GHRequest().addPoint(second).addPoint(third));
assertFalse("should find 2->3", rsp23.hasErrors());
assertEquals(176608.9, rsp23.getBest().getDistance(), .1);
GHResponse grsp = instance.route(new GHRequest().addPoint(first).addPoint(second).addPoint(third));
assertFalse("should find 1->2->3", grsp.hasErrors());
PathWrapper rsp = grsp.getBest();
assertEquals(rsp12.getBest().getDistance() + rsp23.getBest().getDistance(), rsp.getDistance(), 1e-6);
assertEquals(5, rsp.getPoints().getSize());
assertEquals(5, rsp.getInstructions().size());
assertEquals(Instruction.REACHED_VIA, rsp.getInstructions().get(1).getSign());
}
use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.
the class LandmarkStorageTest method testWithBorderBlocking.
@Test
public void testWithBorderBlocking() {
AbstractRoutingAlgorithmTester.initBiGraph(ghStorage);
LandmarkStorage storage = new LandmarkStorage(ghStorage, new RAMDirectory(), 2, new FastestWeighting(encoder), TraversalMode.NODE_BASED);
final SpatialRule ruleRight = new DefaultSpatialRule() {
@Override
public String getId() {
return "right";
}
};
final SpatialRule ruleLeft = new DefaultSpatialRule() {
@Override
public String getId() {
return "left";
}
};
final SpatialRuleLookup lookup = new SpatialRuleLookup() {
@Override
public SpatialRule lookupRule(double lat, double lon) {
if (lon > 0.00105)
return ruleRight;
return ruleLeft;
}
@Override
public SpatialRule lookupRule(GHPoint point) {
return lookupRule(point.lat, point.lon);
}
@Override
public void addRule(SpatialRule rule) {
}
@Override
public int getSpatialId(SpatialRule rule) {
throw new IllegalStateException();
}
@Override
public BBox getBounds() {
throw new IllegalStateException();
}
@Override
public int size() {
return 2;
}
};
storage.setSpatialRuleLookup(lookup);
storage.setMinimumNodes(2);
storage.createLandmarks();
assertEquals(3, storage.getSubnetworksWithLandmarks());
}
use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.
the class QueryGraphTest method testInternalAPIOriginalTraversalKey.
@Test
public void testInternalAPIOriginalTraversalKey() {
initGraph(g);
EdgeExplorer explorer = g.createEdgeExplorer();
QueryGraph queryGraph = new QueryGraph(g);
EdgeIterator iter = explorer.setBaseNode(1);
assertTrue(iter.next());
int origEdgeId = iter.getEdge();
QueryResult res = createLocationResult(2, 1.5, iter, 1, PILLAR);
queryGraph.lookup(Arrays.asList(res));
assertEquals(new GHPoint(1.5, 1.5), res.getSnappedPoint());
assertEquals(3, res.getClosestNode());
EdgeExplorer qGraphExplorer = queryGraph.createEdgeExplorer();
iter = qGraphExplorer.setBaseNode(3);
assertTrue(iter.next());
assertEquals(0, iter.getAdjNode());
assertEquals(GHUtility.createEdgeKey(1, 0, origEdgeId, false), ((VirtualEdgeIteratorState) queryGraph.getEdgeIteratorState(iter.getEdge(), 0)).getOriginalTraversalKey());
assertTrue(iter.next());
assertEquals(1, iter.getAdjNode());
assertEquals(GHUtility.createEdgeKey(0, 1, origEdgeId, false), ((VirtualEdgeIteratorState) queryGraph.getEdgeIteratorState(iter.getEdge(), 1)).getOriginalTraversalKey());
}
Aggregations