1
我在我的java項目中通過maven使用了graphhopper 0.8。我創建一個folling代碼Graphhopper:當圖形的邊界無效時,無法創建位置索引
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() – Karussell
在準備結束時調用'graph.close()'和'index.close()'不會改變任何內容。較早調用它會增加其他錯誤,主要是因爲圖形關閉,因此不能從空圖創建索引。 在添加完所有節點和鏈接後添加'graph.freeze()'沒有區別。 ''graph.baseGraph.loadNodesHeader()'在'gb.load()'成功調用' – Andreas
我使用笛卡爾EPSG:25832,座標範圍爲10E06。 'Helper.degreeToInt(double deg)'檢查'Double.MAX_VALUE'。此檢查已通過。然而,5E10的DEGREE_FACTOR的複合結果後來不能在'Integer.MAX_VALUE'上加上'int'?!最終,對磁盤的刷新使我所有的座標都變爲IntMaxVal。那麼,graphhopper僅限於WGS84? – Andreas