1

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?

Andreas
  • 127
  • 1
  • 1
  • 8
  • Good question :) ! Looks good from just scanning the code. Can you try graph.close and index.close to make sure all resources are properly released (shouldn't be necessary as you call flush). And can you debug the code and see if BaseGraph.loadNodesHeader is called? And another smaller part is missing: calling ghStorage.freeze() before CH preparation – Karussell Nov 10 '16 at 07:29
  • Calling `graph.close()` and `index.close()` at the end of the preparation does not change anything. Calling it earlier adds other errors mainly because the graph is closes and hence the index cannot be created from an empty graph. Added `graph.freeze()` right after adding all the nodes and links > no difference. `graph.baseGraph.loadNodesHeader()` is called successfully at `gb.load()` – Andreas Nov 10 '16 at 07:56
  • I use the cartesian EPSG:25832 with coords in the range of 10E06. `Helper.degreeToInt(double deg)` checks for `Double.MAX_VALUE`. This check is passed. However, the result of the muliplication with the `DEGREE_FACTOR` of 5E10 cannot be cast to `int` later on without capping at `Integer.MAX_VALUE`?! Eventually, the flush to disk makes all my coordinates end up being IntMaxVal. So, graphhopper is restricted to WGS84? – Andreas Nov 10 '16 at 08:13
  • @Karussell I converted my network to WGS84 and run into [another issue](http://stackoverflow.com/q/40525114/4121087) – Andreas Nov 10 '16 at 10:21

1 Answers1

0

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.

Andreas
  • 127
  • 1
  • 1
  • 8