我在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?
答案 0 :(得分:0)
TL; DR不要使用笛卡尔坐标,而是坚持使用OSM使用的WGS84。
笛卡尔坐标系,例如EPSG:25832可能具有数百万的坐标。在执行一些数学运算后,坐标的幅度可能会进一步增加最终,Graphhopper将坐标存储为整数。也就是说,所有坐标最终都可以为Integer.MAX_VALUE。因此,无效的边界框。