Graphhopper: Cannot create location index when gra

2019-07-24 23:33发布

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?

标签: graphhopper
1条回答
We Are One
2楼-- · 2019-07-25 00:32

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.

查看更多
登录 后发表回答