Search in sources :

Example 31 with GraphHopper

use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.

the class OSMReaderTest method testSort.

@Test
public void testSort() {
    GraphHopper hopper = new GraphHopperFacade(file1).setSortGraph(true).importOrLoad();
    NodeAccess na = hopper.getGraphHopperStorage().getNodeAccess();
    assertEquals(10, na.getLongitude(findID(hopper.getLocationIndex(), 49, 10)), 1e-3);
    assertEquals(51.249, na.getLatitude(findID(hopper.getLocationIndex(), 51.2492152, 9.4317166)), 1e-3);
}
Also used : GraphHopper(com.graphhopper.GraphHopper) Test(org.junit.Test)

Example 32 with GraphHopper

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();
    QueryResult qr = hopper.getLocationIndex().findClosest(0.1, 179.5, EdgeFilter.ALL_EDGES);
    assertTrue(qr.isValid());
    assertEquals(0.1, qr.getSnappedPoint().lat, 0.1);
    assertEquals(179.5, qr.getSnappedPoint().lon, 0.1);
    assertEquals(11, qr.getClosestEdge().getDistance() / 1000, 1);
    qr = hopper.getLocationIndex().findClosest(0.1, -179.6, EdgeFilter.ALL_EDGES);
    assertTrue(qr.isValid());
    assertEquals(0.1, qr.getSnappedPoint().lat, 0.1);
    assertEquals(-179.6, qr.getSnappedPoint().lon, 0.1);
    assertEquals(56, qr.getClosestEdge().getDistance() / 1000, 1);
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) GraphHopper(com.graphhopper.GraphHopper) Test(org.junit.Test)

Example 33 with GraphHopper

use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.

the class OSMReaderTest method testNegativeIds.

@Test
public void testNegativeIds() {
    GraphHopper hopper = new GraphHopperFacade(fileNegIds).importOrLoad();
    Graph graph = hopper.getGraphHopperStorage();
    assertEquals(4, graph.getNodes());
    int n20 = AbstractGraphStorageTester.getIdOf(graph, 52);
    int n10 = AbstractGraphStorageTester.getIdOf(graph, 51.2492152);
    int n30 = AbstractGraphStorageTester.getIdOf(graph, 51.2);
    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());
    assertTrue(iter.next());
    assertEquals(n30, iter.getAdjNode());
    assertEquals(93147, iter.getDistance(), 1);
    assertTrue(iter.next());
    assertEquals(n10, iter.getAdjNode());
    assertEquals(88643, iter.getDistance(), 1);
}
Also used : GraphHopper(com.graphhopper.GraphHopper) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 34 with GraphHopper

use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.

the class OSMReaderTest method testReadEleFromCustomOSM.

@Test
public void testReadEleFromCustomOSM() {
    GraphHopper hopper = new GraphHopperFacade("custom-osm-ele.xml") {

        @Override
        protected DataReader createReader(GraphHopperStorage tmpGraph) {
            return initDataReader(new OSMReader(tmpGraph) {

                @Override
                protected double getElevation(ReaderNode node) {
                    return node.getEle();
                }
            });
        }
    }.setElevation(true).importOrLoad();
    Graph graph = hopper.getGraphHopperStorage();
    int n20 = AbstractGraphStorageTester.getIdOf(graph, 52);
    int n50 = AbstractGraphStorageTester.getIdOf(graph, 49);
    EdgeIteratorState edge = GHUtility.getEdge(graph, n20, n50);
    assertEquals(Helper.createPointList3D(52, 9, -10, 51.25, 9.43, 100, 49, 10, -30), edge.fetchWayGeometry(3));
}
Also used : ReaderNode(com.graphhopper.reader.ReaderNode) GraphHopper(com.graphhopper.GraphHopper) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 35 with GraphHopper

use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.

the class OSMReaderTest method testFoot.

@Test
public void testFoot() {
    GraphHopper hopper = new GraphHopperFacade(file3).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(new DefaultEdgeFilter(footEncoder, false, true));
    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)));
}
Also used : GraphHopper(com.graphhopper.GraphHopper) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Aggregations

GraphHopper (com.graphhopper.GraphHopper)37 Test (org.junit.Test)31 GHPoint (com.graphhopper.util.shapes.GHPoint)17 IOException (java.io.IOException)7 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)6 GHRequest (com.graphhopper.GHRequest)4 GHResponse (com.graphhopper.GHResponse)4 File (java.io.File)4 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)3 Weighting (com.graphhopper.routing.weighting.Weighting)3 CmdArgs (com.graphhopper.util.CmdArgs)3 ReaderNode (com.graphhopper.reader.ReaderNode)2 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)2 PrepareContractionHierarchies (com.graphhopper.routing.ch.PrepareContractionHierarchies)2 PrepareLandmarks (com.graphhopper.routing.lm.PrepareLandmarks)2 EncodingManager (com.graphhopper.routing.util.EncodingManager)2 OneRun (com.graphhopper.routing.util.TestAlgoCollector.OneRun)2 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)2 LocationIndex (com.graphhopper.storage.index.LocationIndex)2 QueryResult (com.graphhopper.storage.index.QueryResult)2