Search in sources :

Example 96 with GraphHopper

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

the class OSMReaderTest method testDoNotRejectEdgeIfFirstNodeIsMissing_issue2221.

@Test
public void testDoNotRejectEdgeIfFirstNodeIsMissing_issue2221() {
    GraphHopper hopper = new GraphHopperFacade("test-osm9.xml").importOrLoad();
    GraphHopperStorage graph = hopper.getGraphHopperStorage();
    assertEquals(2, graph.getNodes());
    assertEquals(1, graph.getEdges());
    AllEdgesIterator iter = graph.getAllEdges();
    iter.next();
    assertEquals(0, iter.getBaseNode());
    assertEquals(1, iter.getAdjNode());
    assertEquals(51.21, graph.getNodeAccess().getLat(0), 1.e-3);
    assertEquals(9.41, graph.getNodeAccess().getLon(0), 1.e-3);
    assertEquals(51.22, graph.getNodeAccess().getLat(1), 1.e-3);
    assertEquals(9.42, graph.getNodeAccess().getLon(1), 1.e-3);
    assertEquals(DistanceCalcEarth.DIST_EARTH.calcDistance(iter.fetchWayGeometry(FetchMode.ALL)), iter.getDistance(), 1.e-3);
    assertEquals(1312.1, iter.getDistance(), 1.e-1);
    assertEquals(1312.1, DistanceCalcEarth.DIST_EARTH.calcDistance(iter.fetchWayGeometry(FetchMode.ALL)), 1.e-1);
    assertFalse(iter.next());
}
Also used : GraphHopper(com.graphhopper.GraphHopper) Test(org.junit.jupiter.api.Test) GraphHopperTest(com.graphhopper.GraphHopperTest)

Example 97 with GraphHopper

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

the class OSMReaderTest method testPreferredLanguage.

@Test
public void testPreferredLanguage() {
    GraphHopper hopper = new GraphHopperFacade(file1, false, "de").importOrLoad();
    GraphHopperStorage graph = hopper.getGraphHopperStorage();
    int n20 = AbstractGraphStorageTester.getIdOf(graph, 52);
    EdgeIterator iter = carOutExplorer.setBaseNode(n20);
    assertTrue(iter.next());
    assertEquals("straße 123, B 122", iter.getName());
    hopper = new GraphHopperFacade(file1, false, "el").importOrLoad();
    graph = hopper.getGraphHopperStorage();
    n20 = AbstractGraphStorageTester.getIdOf(graph, 52);
    iter = carOutExplorer.setBaseNode(n20);
    assertTrue(iter.next());
    assertTrue(iter.next());
    assertEquals("διαδρομή 666", iter.getName());
}
Also used : GraphHopper(com.graphhopper.GraphHopper) Test(org.junit.jupiter.api.Test) GraphHopperTest(com.graphhopper.GraphHopperTest)

Example 98 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.getLon(findID(hopper.getLocationIndex(), 49, 10)), 1e-3);
    assertEquals(51.249, na.getLat(findID(hopper.getLocationIndex(), 51.2492152, 9.4317166)), 1e-3);
}
Also used : GraphHopper(com.graphhopper.GraphHopper) Test(org.junit.jupiter.api.Test) GraphHopperTest(com.graphhopper.GraphHopperTest)

Example 99 with GraphHopper

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

the class OSMReaderTest method testWayReferencesNotExistingAdjNode_issue19.

@Test
public void testWayReferencesNotExistingAdjNode_issue19() {
    GraphHopper hopper = new GraphHopperFacade(file4).importOrLoad();
    Graph graph = hopper.getGraphHopperStorage();
    assertEquals(2, graph.getNodes());
    // the missing node is ignored, but the separated nodes are still connected
    assertEquals(1, graph.getEdges());
    int n10 = AbstractGraphStorageTester.getIdOf(graph, 51.2492152);
    int n30 = AbstractGraphStorageTester.getIdOf(graph, 51.2);
    assertEquals(GHUtility.asSet(n30), GHUtility.getNeighbors(carOutExplorer.setBaseNode(n10)));
}
Also used : GraphHopper(com.graphhopper.GraphHopper) Test(org.junit.jupiter.api.Test) GraphHopperTest(com.graphhopper.GraphHopperTest)

Example 100 with GraphHopper

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

the class OSMReaderTest method testBarrierBetweenWays.

@Test
public void testBarrierBetweenWays() {
    GraphHopper hopper = new GraphHopperFacade("test-barriers2.xml").setMinNetworkSize(0).importOrLoad();
    Graph graph = hopper.getGraphHopperStorage();
    // there are seven ways, but there should also be six barrier edges
    // we first split the loop way into two parts, and then we split the barrier node => 3 edges total
    assertEquals(7 + 6, graph.getEdges());
    int loops = 0;
    AllEdgesIterator iter = graph.getAllEdges();
    while (iter.next()) {
        // there are 'loop' edges, but only between different nodes
        assertNotEquals(iter.getBaseNode(), iter.getAdjNode());
        if (graph.getNodeAccess().getLat(iter.getBaseNode()) == graph.getNodeAccess().getLat(iter.getAdjNode()))
            loops++;
    }
    assertEquals(5, loops);
}
Also used : GraphHopper(com.graphhopper.GraphHopper) Test(org.junit.jupiter.api.Test) GraphHopperTest(com.graphhopper.GraphHopperTest)

Aggregations

GraphHopper (com.graphhopper.GraphHopper)101 Test (org.junit.jupiter.api.Test)62 Profile (com.graphhopper.config.Profile)52 LMProfile (com.graphhopper.config.LMProfile)44 CHProfile (com.graphhopper.config.CHProfile)39 GraphHopperTest (com.graphhopper.GraphHopperTest)25 ArrayList (java.util.ArrayList)24 File (java.io.File)16 Test (org.junit.Test)11 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)10 GHRequest (com.graphhopper.GHRequest)7 GHResponse (com.graphhopper.GHResponse)7 GraphHopperConfig (com.graphhopper.GraphHopperConfig)6 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)6 EncodingManager (com.graphhopper.routing.util.EncodingManager)6 PMap (com.graphhopper.util.PMap)6 GHPoint (com.graphhopper.util.shapes.GHPoint)5 IOException (java.io.IOException)5 Gpx (com.graphhopper.jackson.Gpx)4 MapMatching (com.graphhopper.matching.MapMatching)4