Search in sources :

Example 1 with JsonFeatureConverter

use of com.graphhopper.json.JsonFeatureConverter in project graphhopper by graphhopper.

the class ChangeGraphHelperTest method testApplyChanges.

@Test
public void testApplyChanges() {
    // 0-1-2
    // | |
    // 3-4
    graph.edge(0, 1, 1, true);
    graph.edge(1, 2, 1, true);
    graph.edge(3, 4, 1, true);
    graph.edge(0, 3, 1, true);
    graph.edge(1, 4, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.01, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, 0.01, 0.02);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 3, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 4, 0.00, 0.01);
    LocationIndex locationIndex = new LocationIndexTree(graph, new RAMDirectory()).prepareIndex();
    FlagEncoder encoder = encodingManager.getEncoder("car");
    double defaultSpeed = encoder.getSpeed(GHUtility.getEdge(graph, 0, 1).getFlags());
    AllEdgesIterator iter = graph.getAllEdges();
    while (iter.next()) {
        long flags = GHUtility.getEdge(graph, 0, 1).getFlags();
        assertEquals(defaultSpeed, encoder.getSpeed(flags), .1);
        assertTrue(encoder.isForward(flags));
    }
    Reader reader = new InputStreamReader(getClass().getResourceAsStream("overlaydata1.json"), Helper.UTF_CS);
    ChangeGraphHelper instance = new ChangeGraphHelper(graph, locationIndex);
    JsonFeatureConverter converter = new JsonFeatureConverter(ghson, instance, encodingManager);
    long updates = converter.applyChanges(reader);
    assertEquals(2, updates);
    // assert changed speed and access
    double newSpeed = encoder.getSpeed(GHUtility.getEdge(graph, 0, 1).getFlags());
    assertEquals(10, newSpeed, .1);
    assertTrue(newSpeed < defaultSpeed);
    assertFalse(encoder.isForward(GHUtility.getEdge(graph, 3, 4).getFlags()));
}
Also used : AllEdgesIterator(com.graphhopper.routing.util.AllEdgesIterator) InputStreamReader(java.io.InputStreamReader) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) JsonFeatureConverter(com.graphhopper.json.JsonFeatureConverter) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) LocationIndex(com.graphhopper.storage.index.LocationIndex) RAMDirectory(com.graphhopper.storage.RAMDirectory) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) Test(org.junit.Test)

Aggregations

JsonFeatureConverter (com.graphhopper.json.JsonFeatureConverter)1 AllEdgesIterator (com.graphhopper.routing.util.AllEdgesIterator)1 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)1 RAMDirectory (com.graphhopper.storage.RAMDirectory)1 LocationIndex (com.graphhopper.storage.index.LocationIndex)1 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 Test (org.junit.Test)1