Graphhopper: Cannot create location index when graph has invalid bounds

北城余情 提交于 2019-12-11 05:38:24

问题


I am using graphhopper 0.8 via maven in my java project. I create a network with the folling code

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

At this point, the bounding box saved in the graph shows the correct numbers. Files are written to disk including the "location_index". However, reloading the data gets me the following error

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)

The reading is done with the following code

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

So LocationIndexTree.loadExisting runs fine until entering prepareAlgo. At this point, the graph is loaded. However, the bounding box is not set and kept at the defaults?! Reading the location index does not update the bounding box. Hence, the error downstreams. What am I doing wrong? How do I preserve the bounding box in the first place? How to reconstruct the bbox?


回答1:


TL;DR Don't use cartesian coordinates but stick to the WGS84 used by OSM.

A cartesian coordinate system like e.g. EPSG:25832 may have coordinates in the range of millions. After performing some math the coordinates may further increase in magnitude. Eventually, Graphhopper will store the coordinates as integers. That is, all coordinates may end up as Integer.MAX_VALUE. Hence, an invalid bounding box.



来源:https://stackoverflow.com/questions/40514141/graphhopper-cannot-create-location-index-when-graph-has-invalid-bounds

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!