use of com.graphhopper.routing.util.AllEdgesIterator in project graphhopper by graphhopper.
the class AbstractEdgeElevationInterpolator method interpolateElevationsOfTowerNodes.
private void interpolateElevationsOfTowerNodes() {
final AllEdgesIterator edge = storage.getAllEdges();
final GHBitSet visitedEdgeIds = new GHBitSetImpl(edge.getMaxId());
final EdgeExplorer edgeExplorer = storage.createEdgeExplorer();
while (edge.next()) {
final int edgeId = edge.getEdge();
if (isInterpolatableEdge(edge)) {
if (!visitedEdgeIds.contains(edgeId)) {
interpolateEdge(edge, visitedEdgeIds, edgeExplorer);
}
}
visitedEdgeIds.add(edgeId);
}
}
use of com.graphhopper.routing.util.AllEdgesIterator in project graphhopper by graphhopper.
the class Location2IDFullWithEdgesIndex method findClosest.
@Override
public QueryResult findClosest(double queryLat, double queryLon, EdgeFilter filter) {
if (isClosed())
throw new IllegalStateException("You need to create a new LocationIndex instance as it is already closed");
QueryResult res = new QueryResult(queryLat, queryLon);
double foundDist = Double.MAX_VALUE;
AllEdgesIterator iter = graph.getAllEdges();
while (iter.next()) {
if (!filter.accept(iter)) {
continue;
}
for (int i = 0, node; i < 2; i++) {
if (i == 0) {
node = iter.getBaseNode();
} else {
node = iter.getAdjNode();
}
double fromLat = nodeAccess.getLatitude(node);
double fromLon = nodeAccess.getLongitude(node);
double fromDist = calc.calcDist(fromLat, fromLon, queryLat, queryLon);
if (fromDist < 0)
continue;
if (fromDist < foundDist) {
res.setQueryDistance(fromDist);
res.setClosestEdge(iter.detach(false));
res.setClosestNode(node);
foundDist = fromDist;
}
// process the next stuff only for baseNode
if (i > 0)
continue;
int toNode = iter.getAdjNode();
double toLat = nodeAccess.getLatitude(toNode);
double toLon = nodeAccess.getLongitude(toNode);
if (calc.validEdgeDistance(queryLat, queryLon, fromLat, fromLon, toLat, toLon)) {
double distEdge = calc.calcDenormalizedDist(calc.calcNormalizedEdgeDistance(queryLat, queryLon, fromLat, fromLon, toLat, toLon));
if (distEdge < foundDist) {
res.setQueryDistance(distEdge);
res.setClosestNode(node);
res.setClosestEdge(iter);
if (fromDist > calc.calcDist(toLat, toLon, queryLat, queryLon))
res.setClosestNode(toNode);
foundDist = distEdge;
}
}
}
}
return res;
}
use of com.graphhopper.routing.util.AllEdgesIterator in project graphhopper by graphhopper.
the class GHUtility method printEdgeInfo.
public static void printEdgeInfo(final Graph g, FlagEncoder encoder) {
System.out.println("-- Graph n:" + g.getNodes() + " e:" + g.getAllEdges().getMaxId() + " ---");
AllEdgesIterator iter = g.getAllEdges();
while (iter.next()) {
String sc = "";
if (iter instanceof AllCHEdgesIterator) {
AllCHEdgesIterator aeSkip = (AllCHEdgesIterator) iter;
sc = aeSkip.isShortcut() ? "sc" : " ";
}
String fwdStr = iter.isForward(encoder) ? "fwd" : " ";
String bckStr = iter.isBackward(encoder) ? "bckwd" : "";
System.out.println(sc + " " + iter + " " + fwdStr + " " + bckStr);
}
}
use of com.graphhopper.routing.util.AllEdgesIterator 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()));
}
use of com.graphhopper.routing.util.AllEdgesIterator in project graphhopper by graphhopper.
the class Location2IDFullIndex method findClosest.
@Override
public QueryResult findClosest(double queryLat, double queryLon, EdgeFilter edgeFilter) {
if (isClosed())
throw new IllegalStateException("You need to create a new LocationIndex instance as it is already closed");
QueryResult res = new QueryResult(queryLat, queryLon);
Circle circle = null;
AllEdgesIterator iter = graph.getAllEdges();
while (iter.next()) {
if (!edgeFilter.accept(iter))
continue;
for (int node, i = 0; i < 2; i++) {
if (i == 0) {
node = iter.getBaseNode();
} else {
node = iter.getAdjNode();
}
double tmpLat = nodeAccess.getLatitude(node);
double tmpLon = nodeAccess.getLongitude(node);
double dist = calc.calcDist(tmpLat, tmpLon, queryLat, queryLon);
if (circle == null || dist < calc.calcDist(circle.getLat(), circle.getLon(), queryLat, queryLon)) {
res.setClosestEdge(iter.detach(false));
res.setClosestNode(node);
res.setQueryDistance(dist);
if (dist <= 0)
break;
circle = new Circle(tmpLat, tmpLon, dist, calc);
}
}
}
return res;
}
Aggregations