[GraphHopper] Adding custom weight to edge

Markus s0870203 at mail.zih.tu-dresden.de
Mon Mar 9 13:11:49 UTC 2015


Hi Peter,

Any hint how I get the QueryResult in the calcWeight?
So far I was using:

public class MyWeighting extends PriorityWeighting {
...
@Override
public double calcWeight( EdgeIteratorState edgeState, boolean reverse, int 
prevOrNextEdgeId )
{
	double weight = super.calcWeight(edgeState, reverse, prevOrNextEdgeId);
	if (Double.isInfinite(weight))
		return Double.POSITIVE_INFINITY;
	double tempWeight =weight / (0.5 
	+encoder.getDouble(edgeState.getFlags(), KEY));
	int calcEdge=edgeState.getEdge();
	if(myWeightList.containsKey(calcEdge)) {
		//do some calculation
		return (myWeight!=0 ? tempWeight*myWeight : tempWeight);
	}
	else
	return tempWeight;

for the creation of myWeightList I'm use
QueryResult myQR = index.findClosest(tmpPoint.getLat(),tmpPoint.getLon(), 
EdgeFilter.ALL_EDGES);
in a different class.

I could use for calcEdge the findClosest() with 
edgeState.fetchWayGeometry.getLat/getLon and create a QueryResult
but I guess that is not the way to go. 


btw I forgot to mention I'm using Graphhopper 4.0.0, if that is important.

thx Markus

On Monday 09 March 2015 11:07:15 Peter wrote:
> Hi Markus,
> 
> you can use a method like this. Try QueryResult.closestEdge.getEdge
> instead of the edgeIds from the EdgeIterator of that query point as they
> are 'virtual edges'.
> 
> But be aware that if you reimport from a new OSM file you will need to
> re-do the edgeID mapping.
> 
> Regards,
> Peter
> 
> On 08.03.2015 15:07, Markus wrote:
> > Hey,
> > 
> > I'm having an Android App and bunch of GPS points I'm loading them
> > from a server. Each GPS point has a weighting value assigned and should
> > alter the weight of an edge they belonging to.
> > 
> > I'm struggling with assigning my data to the right edges to use them for
> > the path calculation.
> > 
> > I'm using getLocationIndex() findClosest() and assign the weight to the
> > edge and store this data in a Map during an AsyncTask.
> > In the weight calculation I'm checking if the edge in my Map is the same
> > as
> > the one graphhopper is handling at the moment and if so add the weighting
> > to the calculation.
> > 
> > But the edges stored in the Map are different from the once I get with
> > getEdge() from EdgeIteratorState (the doc also states that I shouldn't
> > make
> > any  assumptions about the concrete values).
> > Is there a way to get the EdgeID so I can store my information in the Map?
> > 
> > Is there a nice way to solve that?
> > 
> > 
> > Thx Markus
> > 
> > _______________________________________________
> > GraphHopper mailing list
> > GraphHopper at openstreetmap.org
> > https://lists.openstreetmap.org/listinfo/graphhopper
> 
> _______________________________________________
> GraphHopper mailing list
> GraphHopper at openstreetmap.org
> https://lists.openstreetmap.org/listinfo/graphhopper




More information about the GraphHopper mailing list