1

I am currently using GraphHopper within an application that detects whether a customer's route goes past a specific point of interest (PoI). One PoI has one or more roads through which a customer can pass it (predefined for each PoI).

The fastest way to do this, I think, is to find each customer route, and see whether the edges within a route include any edges that pass a PoI. The following code finds all of the edges closest to the points stored within a GHResponse object (called 'route' in the code below).

QueryResult qr;
HashMap<String, EdgeIteratorState> routeEdges= new HashMap<String, EdgeIteratorState>();
for(GHPoint p:route.getPoints()){
    qr = index.findClosest(p.getLat(), p.getLon(), EdgeFilter.ALL_EDGES );
    routeEdges.put(qr.getClosestEdge().toString(), qr.getClosestEdge());
}

This uses end-points of each road and searches for the closest edge, which I might return any of the edges at that node. I'd much prefer a list of edgeID's within the route, so I could compare them to the edges for each PoI instead.

Any advice would be much appreciated. Cheers!

4

1 回答 1

0

感谢 Karussell 的建议,我创建了自己的自定义 GraphHopper 对象,该对象实现了一种特定方法来返回路线中使用的边。

public class GraphHopperWithPaths extends GraphHopper {

public List<Integer> routePaths(double startY, double startX, double endY, double endX){

    //Examine a route and return edgeIDs that GraphHopper uses
    LocationIndex index = this.getLocationIndex();
    GHRequest request = new GHRequest(startY, startX, endY, endX);
    GHResponse response = new GHResponse();
    List<Path> paths = getPaths(request, response);
    List<Integer> edges = new ArrayList<Integer>();
    for(Path p:paths){
        for(EdgeIteratorState e:p.calcEdges()){
            edges.add(e.getEdge());
        }
    }
    if (response.hasErrors()) return null;

    //Get edges for start and end point as well
    QueryResult qr = index.findClosest(startY, startX, EdgeFilter.ALL_EDGES );
    edges.add(qr.getClosestEdge().getEdge());
    qr = index.findClosest(endY, endX, EdgeFilter.ALL_EDGES );
    edges.add(qr.getClosestEdge().getEdge());

    return edges;
}

}

此方法不返回路由本身,这意味着如果您需要路由和边缘,则应修改它。同时运行这个自定义 GraphHopper 对象的routeroutePaths方法效率会很低。

于 2015-05-01T02:48:19.400 回答