Graphhopper:当图形具有无效边界时无法创建位置索引
Graphhopper: Cannot create location index when graph has invalid bounds
我在我的 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?
TL;DR 不要使用笛卡尔坐标,而是坚持使用 OSM 使用的 WGS84。
笛卡尔坐标系,例如EPSG:25832可能有百万范围内的坐标。在执行一些数学运算后,坐标的幅度可能会进一步增加。最终,Graphhopper 会将坐标存储为整数。也就是说,所有的坐标可能最终都是Integer.MAX_VALUE。因此,边界框无效。
我在我的 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?
TL;DR 不要使用笛卡尔坐标,而是坚持使用 OSM 使用的 WGS84。
笛卡尔坐标系,例如EPSG:25832可能有百万范围内的坐标。在执行一些数学运算后,坐标的幅度可能会进一步增加。最终,Graphhopper 会将坐标存储为整数。也就是说,所有的坐标可能最终都是Integer.MAX_VALUE。因此,边界框无效。