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()));
}
Aggregations