【问题标题】:In Graphhopper, how can I retrieve the set of edges contained in a route?在 Graphhopper 中,如何检索路线中包含的边集?
【发布时间】:2015-05-01 10:48:19
【问题描述】:

我目前在一个应用程序中使用 GraphHopper,该应用程序检测客户的路线是否经过特定兴趣点 (PoI)。一个 PoI 有一条或多条客户可以通过的道路(为每个 PoI 预定义)。

我认为,最快的方法是找到每条客户路线,并查看路线中的边是否包含通过 PoI 的任何边。下面的代码查找所有最接近存储在 GHResponse 对象中的点的边(在下面的代码中称为“路线”)。

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

这使用每条道路的端点并搜索最近的边缘,我可能会返回该节点处的任何边缘。我更喜欢路线中的 edgeID 列表,所以我可以将它们与每个 PoI 的边缘进行比较。

任何建议将不胜感激。干杯!

【问题讨论】:

  • “边缘”是什么意思?路线中包含的线?
  • 目前这个内部没有暴露给 GraphHopper 类中的任何公共方法。因此,您需要使用较低级别的 API。或者您可以重载 GraphHopper.getPaths 并将路径存储在某处,然后调用 path.calcEdges
  • Ubica - GraphHopper 中的一条边(据我所知)是连接两个交汇点/塔式节点的双向边(我可能是错的)。
  • Karussell - 感谢您的提示。除了查看路线的起点和终点外,您的建议似乎很有效。在路线的起点或终点以及 PoI 位于两个塔节点之间的情况下,边缘似乎被不同地描述并且未被检测到。您对此有什么建议吗?
  • GraphHopper 将创建两个虚拟边,但仍具有可用于匹配它们的相同“原始”边。您可以通过 QueryResult.getClosestEdge 获得“原始”边缘

标签: java routing graphhopper


【解决方案1】:

感谢 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 方法效率会很低。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多