I am attempting to run an Isochrone calculation to find all nodes within a time limit of a lat/long. I am getting an error when I give a limit limit longer than a few seconds - presumably because the original lat/long point is appearing in the output of the ShortestPathTree?
I am running a local install of com.graphhopper:graphhopper-core:7.0-pre1 in a Databricks notebook.
For reference, the BaseGraph has 6023015 nodes
My code is as follows:
import com.graphhopper._
import com.graphhopper.config.Profile
import com.graphhopper.config.CHProfile
import com.graphhopper.isochrone.algorithm.ShortestPathTree;
import com.graphhopper.routing.ev.Subnetwork;
import com.graphhopper.routing.querygraph.QueryGraph;
import com.graphhopper.routing.util.DefaultSnapFilter;
import com.graphhopper.routing.util.EncodingManager;
import com.graphhopper.routing.util.TraversalMode;
import com.graphhopper.routing.weighting.Weighting;
import com.graphhopper.storage.index.Snap;
import com.graphhopper.util.GHUtility;
import com.graphhopper.util.PMap;
import java.util.concurrent.atomic.AtomicInteger;
val hopper = new GraphHopper()
hopper.setGraphHopperLocation("[path to cache of PBF road network data]")
hopper.setAllowWrites(false)
hopper.setProfiles(
new Profile("car").setVehicle("car").setWeighting("fastest").setTurnCosts(true)
)
hopper.getCHPreparationHandler().setCHProfiles(
new CHProfile("car")
)
hopper.load()
val encodingManager = hopper.getEncodingManager()
val weighting = hopper.createWeighting(hopper.getProfile("car"), new PMap())
val snap = hopper.getLocationIndex().findClosest(51.501012, -0.126129, new DefaultSnapFilter(weighting, encodingManager.getBooleanEncodedValue(Subnetwork.key("car"))))
val queryGraph = QueryGraph.create(hopper.getBaseGraph(), snap)
===
val tree = new ShortestPathTree(queryGraph, weighting, false, TraversalMode.EDGE_BASED)
tree.setTimeLimit(1*60*1000)
// loop over shortest path tree to see nodes within time limit and total count
val counter = new AtomicInteger(0)
// Initialize empty lists to hold the results
val nodes = scala.collection.mutable.ListBuffer[Int]()
val times = scala.collection.mutable.ListBuffer[Double]()
val distances = scala.collection.mutable.ListBuffer[Double]()
val lons = scala.collection.mutable.ListBuffer[Double]()
val lats = scala.collection.mutable.ListBuffer[Double]()
val speed = 0.0
tree.search(snap.getClosestNode(), label => {
//counter.incrementAndGet()
nodes += label.node // Add node to the nodes list
times += label.time / 60.0 / 1000.0 // Add time to the times list (ms to minutes)
distances += label.distance / 1609.34 // Add distance to the distances list (metres to miles)
val speed = distances.last / times.last * 60.0 // miles per min to miles per hour
lons += queryGraph.getNodeAccess().getLon(label.node)
lats += queryGraph.getNodeAccess().getLat(label.node)
println(s"Node: ${label.node}, Time: ${times.last}, Distance: ${distances.last}, Lat: ${lats.last}, Lon: ${lons.last}, Spd: ${speed}")
})
println(s"Total nodes found: ${counter.get()}")
====
The latter fails to execute with the error: “IllegalArgumentException: node: 6023015 out of bounds [0,6023015[”
Could anyone advise on how to solve this problem?
Thanks