Does GraphHopper support dynamic edge weights?

前端 未结 1 796
闹比i
闹比i 2020-12-17 05:57

We are thinking to use it in our project where we need to do a route planner. The first problem we had is that we have very dyanimc variables representing our weight values;

相关标签:
1条回答
  • 2020-12-17 06:42

    To modify the speed or distance of an edge you need to get an EdgeIteratorState (e.g. from a coordinate) and then set the flags or distance. Here is a code snippet:

    // find edge for lat,lon point
    QueryResult qr = locationIndex.findClosest(lat, lon, EdgeFilter.ALL_EDGES);
    if(!qr.isValid())
          throw RuntimeException("Cannot find nearby location " + lat+","+lon);
    EdgeIteratorState edge = qr.getClosestEdge();
    // use existing flags to reuse access information
    long existingFlags = edge.getFlags();
    // set speed
    edge.setFlags(carFlagEncoder.setSpeed(existingFlags, newSpeed));
    // set distance
    edge.setDistance(newDistance);
    
    0 讨论(0)
提交回复
热议问题