Search in sources :

Example 41 with GraphHopper

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(0));
    assertTrue(iter.isForward(carEncoder));
    assertTrue(iter.isBackward(carEncoder));
    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.isForward(carEncoder));
    assertTrue(iter.isBackward(carEncoder));
    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.getLongitude(findID(hopper.getLocationIndex(), 51.2, 9.4)), 1e-3);
    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);
    // node 40 is on the way between 30 and 50 => 9.0
    assertEquals(9, na.getLongitude(findID(hopper.getLocationIndex(), 51.25, 9.43)), 1e-3);
}
Also used : GraphHopper(com.graphhopper.GraphHopper) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 42 with GraphHopper

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

the class GraphHopperStorageForDataFlagEncoderTest method testStorageProperties.

@Test
public void testStorageProperties() {
    graph = new GraphBuilder(encodingManager).setStore(true).setLocation(defaultGraphLoc).create();
    // 0-1
    ReaderWay way_0_1 = new ReaderWay(27l);
    way_0_1.setTag("highway", "primary");
    way_0_1.setTag("maxheight", "4.4");
    graph.edge(0, 1, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
    graph.getEdgeIteratorState(0, 1).setFlags(encoder.handleWayTags(way_0_1, 1, 0));
    // 1-2
    ReaderWay way_1_2 = new ReaderWay(28l);
    way_1_2.setTag("highway", "primary");
    way_1_2.setTag("maxweight", "45");
    graph.edge(1, 2, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, 0.02, 0.02);
    graph.getEdgeIteratorState(1, 2).setFlags(encoder.handleWayTags(way_1_2, 1, 0));
    // 2-0
    ReaderWay way_2_0 = new ReaderWay(29l);
    way_2_0.setTag("highway", "primary");
    way_2_0.setTag("maxwidth", "5");
    graph.edge(2, 0, 1, true);
    graph.getEdgeIteratorState(2, 0).setFlags(encoder.handleWayTags(way_2_0, 1, 0));
    graph.flush();
    graph.close();
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setCHEnabled(false).importOrLoad();
    EncodingManager em = hopper.getEncodingManager();
    assertNotNull(em);
    assertEquals(1, em.fetchEdgeEncoders().size());
    FlagEncoder flagEncoder = em.fetchEdgeEncoders().get(0);
    assertTrue(flagEncoder instanceof DataFlagEncoder);
    DataFlagEncoder dataFlagEncoder = (DataFlagEncoder) flagEncoder;
    assertTrue(dataFlagEncoder.isStoreHeight());
    assertTrue(dataFlagEncoder.isStoreWeight());
    assertFalse(dataFlagEncoder.isStoreWidth());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) DataFlagEncoder(com.graphhopper.routing.util.DataFlagEncoder) DataFlagEncoder(com.graphhopper.routing.util.DataFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) ReaderWay(com.graphhopper.reader.ReaderWay) GraphHopper(com.graphhopper.GraphHopper) Test(org.junit.Test)

Aggregations

GraphHopper (com.graphhopper.GraphHopper)42 Test (org.junit.Test)34 GHPoint (com.graphhopper.util.shapes.GHPoint)17 IOException (java.io.IOException)8 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)7 GHRequest (com.graphhopper.GHRequest)4 GHResponse (com.graphhopper.GHResponse)4 File (java.io.File)4 EncodingManager (com.graphhopper.routing.util.EncodingManager)3 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)3 Weighting (com.graphhopper.routing.weighting.Weighting)3 CmdArgs (com.graphhopper.util.CmdArgs)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 JsonFeatureCollection (com.graphhopper.json.geo.JsonFeatureCollection)2 ReaderNode (com.graphhopper.reader.ReaderNode)2 ReaderWay (com.graphhopper.reader.ReaderWay)2 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)2 PrepareContractionHierarchies (com.graphhopper.routing.ch.PrepareContractionHierarchies)2 PrepareLandmarks (com.graphhopper.routing.lm.PrepareLandmarks)2 OneRun (com.graphhopper.routing.util.TestAlgoCollector.OneRun)2