【发布时间】:2016-11-09 19:01:22
【问题描述】:
我在我的 java 项目中通过 maven 使用 graphhopper 0.8。我使用以下代码创建了一个网络
FlagEncoder encoder = new CarFlagEncoder();
EncodingManager em = new EncodingManager(encoder);
// Creating and saving the graph
GraphBuilder gb = new GraphBuilder(em).
setLocation(testDir).
setStore(true).
setCHGraph(new FastestWeighting(encoder));
GraphHopperStorage graph = gb.create();
for (Node node : ALL NODES OF MY NETWORK) {
graph.getNodeAccess().setNode(uniqueNodeId, nodeX, nodeY);
}
for (Link link : ALL LINKS OF MY NETWORK) {
EdgeIteratorState edge = graph.edge(fromNodeId, toNodeId);
edge.setDistance(linkLength);
edge.setFlags(encoder.setProperties(linkSpeedInMeterPerSecond * 3.6, true, false));
}
Weighting weighting = new FastestWeighting(encoder);
PrepareContractionHierarchies pch = new PrepareContractionHierarchies(graph.getDirectory(), graph, graph.getGraph(CHGraph.class), weighting, TraversalMode.NODE_BASED);
pch.doWork();
graph.flush();
LocationIndex index = new LocationIndexTree(graph.getBaseGraph(), graph.getDirectory());
index.prepareIndex();
index.flush();
此时,图表中保存的边界框显示了正确的数字。文件被写入磁盘,包括“location_index”。但是,重新加载数据会出现以下错误
Exception in thread "main" java.lang.IllegalStateException: Cannot create location index when graph has invalid bounds: 1.7976931348623157E308,1.7976931348623157E308,1.7976931348623157E308,1.7976931348623157E308
at com.graphhopper.storage.index.LocationIndexTree.prepareAlgo(LocationIndexTree.java:132)
at com.graphhopper.storage.index.LocationIndexTree.prepareIndex(LocationIndexTree.java:287)
使用以下代码完成读取
FlagEncoder encoder = new CarFlagEncoder();
EncodingManager em = new EncodingManager(encoder);
GraphBuilder gb = new GraphBuilder(em).
setLocation(testDir).
setStore(true).
setCHGraph(new FastestWeighting(encoder));
// Load and use the graph
GraphHopperStorage graph = gb.load();
// Load the index
LocationIndex index = new LocationIndexTree(graph.getBaseGraph(), graph.getDirectory());
if (!index.loadExisting()) {
index.prepareIndex();
}
所以LocationIndexTree.loadExisting 运行良好,直到进入prepareAlgo。此时,图表已加载。但是,边界框未设置并保持默认值?!读取位置索引不会更新边界框。因此,下游的错误。我究竟做错了什么?我如何首先保留边界框?如何重建bbox?
【问题讨论】:
-
好问题:)!仅扫描代码看起来不错。您可以尝试 graph.close 和 index.close 以确保所有资源都已正确释放(在您调用 flush 时不应该是必需的)。您可以调试代码并查看是否调用了 BaseGraph.loadNodesHeader 吗?并且缺少另一个较小的部分:在 CH 准备之前调用 ghStorage.freeze()
-
在准备结束时调用
graph.close()和index.close()不会改变任何东西。提前调用它会增加其他错误,主要是因为图表已关闭,因此无法从空图表创建索引。在添加所有节点和链接后立即添加graph.freeze()> 没有区别。graph.baseGraph.loadNodesHeader()在gb.load()调用成功 -
我使用坐标在 10E06 范围内的笛卡尔 EPSG:25832。
Helper.degreeToInt(double deg)检查Double.MAX_VALUE。此项检查通过。但是,与 5E10 的DEGREE_FACTOR相乘的结果不能在以后不加上限Integer.MAX_VALUE的情况下转换为int?!最终,刷新到磁盘使我的所有坐标最终成为 IntMaxVal。那么,graphhopper 仅限于 WGS84 吗? -
@Karussell 我将我的网络转换为 WGS84 并遇到another issue
标签: graphhopper