use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class OSMReaderTest method testCrossBoundary_issue667.
@Test
public void testCrossBoundary_issue667() {
GraphHopper hopper = new GraphHopperFacade("test-osm-waterway.xml").importOrLoad();
Snap snap = hopper.getLocationIndex().findClosest(0.1, 179.5, EdgeFilter.ALL_EDGES);
assertTrue(snap.isValid());
assertEquals(0.1, snap.getSnappedPoint().lat, 0.1);
assertEquals(179.5, snap.getSnappedPoint().lon, 0.1);
assertEquals(11, snap.getClosestEdge().getDistance() / 1000, 1);
snap = hopper.getLocationIndex().findClosest(0.1, -179.6, EdgeFilter.ALL_EDGES);
assertTrue(snap.isValid());
assertEquals(0.1, snap.getSnappedPoint().lat, 0.1);
assertEquals(-179.6, snap.getSnappedPoint().lon, 0.1);
assertEquals(112, snap.getClosestEdge().getDistance() / 1000, 1);
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class OSMReaderTest method testMultipleTurnRestrictions.
@Test
public void testMultipleTurnRestrictions() {
String fileMultipleConditionalTurnRestrictions = "test-multiple-conditional-turn-restrictions.xml";
GraphHopper hopper = new GraphHopperFacade(fileMultipleConditionalTurnRestrictions, true, "").importOrLoad();
Graph graph = hopper.getGraphHopperStorage();
assertEquals(5, graph.getNodes());
TurnCostStorage tcStorage = graph.getTurnCostStorage();
assertNotNull(tcStorage);
int n1 = AbstractGraphStorageTester.getIdOf(graph, 50, 10);
int n2 = AbstractGraphStorageTester.getIdOf(graph, 52, 10);
int n3 = AbstractGraphStorageTester.getIdOf(graph, 52, 11);
int n4 = AbstractGraphStorageTester.getIdOf(graph, 52, 12);
int n5 = AbstractGraphStorageTester.getIdOf(graph, 50, 12);
int edge1_2 = GHUtility.getEdge(graph, n1, n2).getEdge();
int edge2_3 = GHUtility.getEdge(graph, n2, n3).getEdge();
int edge3_4 = GHUtility.getEdge(graph, n3, n4).getEdge();
int edge4_5 = GHUtility.getEdge(graph, n4, n5).getEdge();
int edge5_1 = GHUtility.getEdge(graph, n5, n1).getEdge();
DecimalEncodedValue carTCEnc = hopper.getEncodingManager().getDecimalEncodedValue(TurnCost.key("car"));
DecimalEncodedValue bikeTCEnc = hopper.getEncodingManager().getDecimalEncodedValue(TurnCost.key("bike"));
// (1-2)->(2-3) no_right_turn for motorcar and bus
assertTrue(tcStorage.get(carTCEnc, edge1_2, n2, edge2_3) > 0);
assertEquals(0, tcStorage.get(bikeTCEnc, edge1_2, n2, edge2_3), .1);
// (3-4)->(4-5) no_right_turn for motorcycle and motorcar
assertTrue(Double.isInfinite(tcStorage.get(carTCEnc, edge3_4, n4, edge4_5)));
assertEquals(0, tcStorage.get(bikeTCEnc, edge3_4, n4, edge4_5), .1);
// (5-1)->(1-2) no_right_turn for bus and psv except for motorcar and bicycle
assertEquals(0, tcStorage.get(carTCEnc, edge4_5, n5, edge5_1), .1);
assertEquals(0, tcStorage.get(bikeTCEnc, edge4_5, n5, edge5_1), .1);
// (5-1)->(1-2) no_right_turn for motorcar and motorcycle except for bus and bicycle
assertTrue(Double.isInfinite(tcStorage.get(carTCEnc, edge5_1, n1, edge1_2)));
assertEquals(0, tcStorage.get(bikeTCEnc, edge5_1, n1, edge1_2), .1);
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class OSMReaderTest method testReadEleFromDataProvider.
@Test
public void testReadEleFromDataProvider() {
GraphHopper hopper = new GraphHopperFacade("test-osm5.xml");
// get N10E046.hgt.zip
ElevationProvider provider = new SRTMProvider(GraphHopperTest.DIR);
hopper.setElevationProvider(provider);
hopper.importOrLoad();
Graph graph = hopper.getGraphHopperStorage();
int n10 = AbstractGraphStorageTester.getIdOf(graph, 49.501);
int n30 = AbstractGraphStorageTester.getIdOf(graph, 49.5011);
int n50 = AbstractGraphStorageTester.getIdOf(graph, 49.5001);
EdgeIteratorState edge = GHUtility.getEdge(graph, n50, n30);
assertEquals(Helper.createPointList3D(49.5001, 11.501, 426, 49.5002, 11.5015, 441, 49.5011, 11.502, 410.0), edge.fetchWayGeometry(FetchMode.ALL));
edge = GHUtility.getEdge(graph, n10, n50);
assertEquals(Helper.createPointList3D(49.501, 11.5001, 383.0, 49.5001, 11.501, 426.0), edge.fetchWayGeometry(FetchMode.ALL));
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class OSMReaderTest method testMain.
@Test
public void testMain() {
GraphHopper hopper = new GraphHopperFacade(file1).importOrLoad();
GraphHopperStorage graph = hopper.getGraphHopperStorage();
assertNotNull(graph.getProperties().get("datareader.import.date"));
assertNotEquals("", graph.getProperties().get("datareader.import.date"));
assertEquals("2013-01-02T01:10:14Z", graph.getProperties().get("datareader.data.date"));
assertEquals(4, graph.getNodes());
int n20 = AbstractGraphStorageTester.getIdOf(graph, 52);
int n10 = AbstractGraphStorageTester.getIdOf(graph, 51.2492152);
int n30 = AbstractGraphStorageTester.getIdOf(graph, 51.2);
int n50 = AbstractGraphStorageTester.getIdOf(graph, 49);
assertEquals(GHUtility.asSet(n20), GHUtility.getNeighbors(carOutExplorer.setBaseNode(n10)));
assertEquals(3, GHUtility.count(carOutExplorer.setBaseNode(n20)));
assertEquals(GHUtility.asSet(n20), GHUtility.getNeighbors(carOutExplorer.setBaseNode(n30)));
EdgeIterator iter = carOutExplorer.setBaseNode(n20);
assertTrue(iter.next());
assertEquals("street 123, B 122", iter.getName());
assertEquals(n50, iter.getAdjNode());
AbstractGraphStorageTester.assertPList(Helper.createPointList(51.25, 9.43), iter.fetchWayGeometry(FetchMode.PILLAR_ONLY));
assertTrue(iter.get(carAccessEnc));
assertTrue(iter.getReverse(carAccessEnc));
assertTrue(iter.next());
assertEquals("route 666", iter.getName());
assertEquals(n30, iter.getAdjNode());
assertEquals(93147, iter.getDistance(), 1);
assertTrue(iter.next());
assertEquals("route 666", iter.getName());
assertEquals(n10, iter.getAdjNode());
assertEquals(88643, iter.getDistance(), 1);
assertTrue(iter.get(carAccessEnc));
assertTrue(iter.getReverse(carAccessEnc));
assertFalse(iter.next());
// get third added location id=30
iter = carOutExplorer.setBaseNode(n30);
assertTrue(iter.next());
assertEquals("route 666", iter.getName());
assertEquals(n20, iter.getAdjNode());
assertEquals(93146.888, iter.getDistance(), 1);
NodeAccess na = graph.getNodeAccess();
assertEquals(9.4, na.getLon(findID(hopper.getLocationIndex(), 51.2, 9.4)), 1e-3);
assertEquals(10, na.getLon(findID(hopper.getLocationIndex(), 49, 10)), 1e-3);
assertEquals(51.249, na.getLat(findID(hopper.getLocationIndex(), 51.2492152, 9.4317166)), 1e-3);
// node 40 is on the way between 30 and 50 => 9.0
assertEquals(9, na.getLon(findID(hopper.getLocationIndex(), 51.25, 9.43)), 1e-3);
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class OSMReaderTest method testFoot.
@Test
public void testFoot() {
GraphHopper hopper = new GraphHopperFacade(file3).setMinNetworkSize(0).importOrLoad();
Graph graph = hopper.getGraphHopperStorage();
int n10 = AbstractGraphStorageTester.getIdOf(graph, 11.1);
int n20 = AbstractGraphStorageTester.getIdOf(graph, 12);
int n30 = AbstractGraphStorageTester.getIdOf(graph, 11.2);
int n40 = AbstractGraphStorageTester.getIdOf(graph, 11.3);
int n50 = AbstractGraphStorageTester.getIdOf(graph, 10);
assertEquals(GHUtility.asSet(n20, n40), GHUtility.getNeighbors(carAllExplorer.setBaseNode(n10)));
assertEquals(GHUtility.asSet(), GHUtility.getNeighbors(carOutExplorer.setBaseNode(n30)));
assertEquals(GHUtility.asSet(n10, n30, n40), GHUtility.getNeighbors(carAllExplorer.setBaseNode(n20)));
assertEquals(GHUtility.asSet(n30, n40), GHUtility.getNeighbors(carOutExplorer.setBaseNode(n20)));
EdgeExplorer footOutExplorer = graph.createEdgeExplorer(AccessFilter.outEdges(footEncoder.getAccessEnc()));
assertEquals(GHUtility.asSet(n20, n50), GHUtility.getNeighbors(footOutExplorer.setBaseNode(n10)));
assertEquals(GHUtility.asSet(n20, n50), GHUtility.getNeighbors(footOutExplorer.setBaseNode(n30)));
assertEquals(GHUtility.asSet(n10, n30), GHUtility.getNeighbors(footOutExplorer.setBaseNode(n20)));
}
Aggregations