use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class LocationIndexExample method lowLevelLocationIndex.
public static void lowLevelLocationIndex() {
// If you don't use the GraphHopper class you have to use the low level API:
GraphHopperStorage graph = new GraphBuilder(EncodingManager.create(new CarFlagEncoder())).create();
graph.edge(0, 1).setName("test edge");
graph.getNodeAccess().setNode(0, 12, 42);
graph.getNodeAccess().setNode(1, 12.01, 42.01);
LocationIndexTree index = new LocationIndexTree(graph.getBaseGraph(), graph.getDirectory());
index.setResolution(300);
index.setMaxRegionSearch(4);
if (!index.loadExisting())
index.prepareIndex();
Snap snap = index.findClosest(12, 42, EdgeFilter.ALL_EDGES);
EdgeIteratorState edge = snap.getClosestEdge();
assert edge.getName().equals("test edge");
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class AlternativeRouteCH method sharedDistance.
private double sharedDistance(Path path) {
double sharedDistance = 0.0;
List<EdgeIteratorState> edges = path.calcEdges();
for (EdgeIteratorState edge : edges) {
if (nodesInCurrentAlternativeSetContains(edge.getBaseNode()) && nodesInCurrentAlternativeSetContains(edge.getAdjNode())) {
sharedDistance += edge.getDistance();
}
}
return sharedDistance;
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class AlternativeRouteEdgeCH method tTest.
private boolean tTest(Path path, int vIndex) {
if (path.getEdgeCount() == 0)
return true;
double detourDistance = detourDistance(path);
double T = 0.5 * localOptimalityFactor * detourDistance;
EdgeIteratorState fromNode = getPreviousNodeTMetersAway(path, vIndex, T);
EdgeIteratorState toNode = getNextNodeTMetersAway(path, vIndex, T);
DijkstraBidirectionEdgeCHNoSOD tRouter = new DijkstraBidirectionEdgeCHNoSOD(graph);
Path tPath = tRouter.calcPath(fromNode.getBaseNode(), toNode.getAdjNode(), fromNode.getEdge(), toNode.getEdge());
extraVisitedNodes += tRouter.getVisitedNodes();
IntIndexedContainer tNodes = tPath.calcNodes();
int v = path.calcNodes().get(vIndex);
return tNodes.contains(v);
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class Path method calcNodes.
/**
* @return the uncached node indices of the tower nodes in this path.
*/
public IntIndexedContainer calcNodes() {
final IntArrayList nodes = new IntArrayList(edgeIds.size() + 1);
if (edgeIds.isEmpty()) {
if (isFound()) {
nodes.add(endNode);
}
return nodes;
}
int tmpNode = getFromNode();
nodes.add(tmpNode);
forEveryEdge(new EdgeVisitor() {
@Override
public void next(EdgeIteratorState eb, int index, int prevEdgeId) {
nodes.add(eb.getAdjNode());
}
@Override
public void finish() {
}
});
return nodes;
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class Path method calcPoints.
/**
* This method calculated a list of points for this path
* <p>
*
* @return the geometry of this path
*/
public PointList calcPoints() {
final PointList points = new PointList(edgeIds.size() + 1, nodeAccess.is3D());
if (edgeIds.isEmpty()) {
if (isFound()) {
points.add(nodeAccess, endNode);
}
return points;
}
int tmpNode = getFromNode();
points.add(nodeAccess, tmpNode);
forEveryEdge(new EdgeVisitor() {
@Override
public void next(EdgeIteratorState eb, int index, int prevEdgeId) {
PointList pl = eb.fetchWayGeometry(FetchMode.PILLAR_AND_ADJ);
for (int j = 0; j < pl.size(); j++) {
points.add(pl, j);
}
}
@Override
public void finish() {
}
});
return points;
}
Aggregations