Skip to content

Commit 5ba0700

Browse files
Optimizing way filter process.
1 parent cbe50e7 commit 5ba0700

File tree

2 files changed

+7
-134
lines changed

2 files changed

+7
-134
lines changed

core/src/main/java/com/graphhopper/reader/OSMReader.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,13 @@ void processWay( OSMWay way )
401401
if(smoothingFilter.equalsIgnoreCase("mean"))
402402
filter = new MeanFilter(tmpDistances, 100);
403403
else
404-
filter = new SimpleKalmanFilter(SimpleKalmanFilter.COMBINED, 6, tmpDistances, 40);
404+
filter = new SimpleKalmanFilter(SimpleKalmanFilter.COMBINED, 6, tmpDistances, 60);
405405

406406
double[] estimatedElevations = filter.smooth(tmpElevations);
407407

408408
for (int i = 0; i < estimatedElevations.length; i++) {
409409
osmNodeId = getNodeMap().get(osmNodeIds.get(i));
410-
updateTmpElevation(osmNodeId, estimatedElevations[i]);
410+
updateTmpElevation(osmNodeId, estimatedElevations[i], (i == 0 || i == estimatedElevations.length - 1));
411411
}
412412
}
413413
}
@@ -620,11 +620,13 @@ public int getInternalNodeIdOfOsmNode( long nodeOsmId )
620620

621621
//TODO update elevation
622622

623-
boolean updateTmpElevation( int id, double ele ){
623+
boolean updateTmpElevation( int id, double ele, boolean average ){
624624
if (id == EMPTY)
625625
return false;
626626
if(id < TOWER_NODE){
627-
ele = (getTmpElevation(id) + ele) / 2;
627+
if(average)
628+
ele = (getTmpElevation(id) + ele) / 2;
629+
628630
id = -id -3;
629631
nodeAccess.setElevation(id, ele);
630632
return true;

core/src/main/java/com/graphhopper/routing/util/BikeGenericFlagEncoder.java

Lines changed: 1 addition & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,16 @@ public class BikeGenericFlagEncoder extends AbstractFlagEncoder
3737
{
3838

3939
private final DistanceCalc distCalc = Helper.DIST_EARTH;
40-
/**
41-
* Reports wether this edge is unpaved.
42-
*/
4340
public static final int PUSHING_SECTION_SPEED = 4;
41+
4442
// Pushing section highways are parts where you need to get off your bike and push it (German: Schiebestrecke)
4543
protected final HashSet<String> pushingSections = new HashSet<String>();
4644
protected final HashSet<String> oppositeLanes = new HashSet<String>();
4745
protected final Set<String> acceptedHighwayTags = new HashSet<String>();
48-
protected final Set<String> preferHighwayTags = new HashSet<String>();
49-
protected final Set<String> avoidHighwayTags = new HashSet<String>();
5046

5147
protected final Set<String> pavedSurfaceTags = new HashSet<String>();
5248
protected final Set<String> unpavedSurfaceTags = new HashSet<String>();
5349

54-
//private final Map<String, Integer> trackTypeSpeeds = new HashMap<String, Integer>();
5550
private final Map<String, Float> surfaceSpeedFactors = new HashMap<String, Float>();
5651
private final Map<Integer, Integer> wayTypeSpeeds = new HashMap<Integer, Integer>();
5752
// convert network tag of bicycle routes into a way route code
@@ -217,15 +212,6 @@ protected BikeGenericFlagEncoder(int speedBits, double speedFactor, int maxTurnC
217212
addPushingSection("pedestrian");
218213
addPushingSection("steps");
219214

220-
221-
/*setCyclingNetworkPreference("icn", 1);
222-
setCyclingNetworkPreference("ncn", 2);
223-
setCyclingNetworkPreference("rcn", 3);
224-
setCyclingNetworkPreference("lcn", 4);
225-
setCyclingNetworkPreference("mtb", PriorityCode.UNCHANGED.getValue());
226-
227-
setCyclingNetworkPreference("deprecated", PriorityCode.AVOID_AT_ALL_COSTS.getValue());*/
228-
229215
setAvoidSpeedLimit(81);
230216
}
231217

@@ -248,10 +234,6 @@ public int defineWayBits( int index, int shift )
248234
wayTypeEncoder = new EncodedValue("WayType", shift, 4, 1, 0, 15, true);
249235
shift += wayTypeEncoder.getBits();
250236

251-
// 3 bits to store preference on specific ways
252-
//priorityWayEncoder = new EncodedValue("PreferWay", shift, 3, 1, 0, 7);
253-
//shift += priorityWayEncoder.getBits();
254-
255237
// 6 bits to store incline
256238
inclineSlopeEncoder = new EncodedDoubleValue("InclineSlope", shift, 6, 1, 0, 40, true);
257239
shift += inclineSlopeEncoder.getBits();
@@ -494,117 +476,6 @@ String getWayName(int wayType, Translation tr )
494476
return wayTypeName;
495477
}
496478

497-
/**
498-
* In this method we prefer cycleways or roads with designated bike access and avoid big roads
499-
* or roads with trams or pedestrian.
500-
* <p>
501-
* @return new priority based on priorityFromRelation and on the tags in OSMWay.
502-
*/
503-
protected int handlePriority( OSMWay way, int priorityFromRelation )
504-
{
505-
TreeMap<Double, Integer> weightToPrioMap = new TreeMap<Double, Integer>();
506-
if (priorityFromRelation == 0)
507-
weightToPrioMap.put(0d, UNCHANGED.getValue());
508-
else
509-
weightToPrioMap.put(110d, priorityFromRelation);
510-
511-
collect(way, weightToPrioMap);
512-
513-
// pick priority with biggest order value
514-
return weightToPrioMap.lastEntry().getValue();
515-
}
516-
517-
// Conversion of class value to priority. See http://wiki.openstreetmap.org/wiki/Class:bicycle
518-
private PriorityCode convertCallValueToPriority( String tagvalue )
519-
{
520-
int classvalue;
521-
try
522-
{
523-
classvalue = Integer.parseInt(tagvalue);
524-
} catch (NumberFormatException e)
525-
{
526-
return PriorityCode.UNCHANGED;
527-
}
528-
529-
switch (classvalue)
530-
{
531-
case 3:
532-
return PriorityCode.BEST;
533-
case 2:
534-
return PriorityCode.VERY_NICE;
535-
case 1:
536-
return PriorityCode.PREFER;
537-
case 0:
538-
return PriorityCode.UNCHANGED;
539-
case -1:
540-
return PriorityCode.AVOID_IF_POSSIBLE;
541-
case -2:
542-
return PriorityCode.REACH_DEST;
543-
case -3:
544-
return PriorityCode.AVOID_AT_ALL_COSTS;
545-
default:
546-
return PriorityCode.UNCHANGED;
547-
}
548-
}
549-
550-
/**
551-
* @param weightToPrioMap associate a weight with every priority. This sorted map allows
552-
* subclasses to 'insert' more important priorities as well as overwrite determined priorities.
553-
*/
554-
void collect( OSMWay way, TreeMap<Double, Integer> weightToPrioMap )
555-
{
556-
String service = way.getTag("service");
557-
String highway = way.getTag("highway");
558-
if (way.hasTag("bicycle", "designated"))
559-
weightToPrioMap.put(100d, PREFER.getValue());
560-
if ("cycleway".equals(highway))
561-
weightToPrioMap.put(100d, VERY_NICE.getValue());
562-
563-
double maxSpeed = getMaxSpeed(way);
564-
if (preferHighwayTags.contains(highway) || maxSpeed > 0 && maxSpeed <= 30)
565-
{
566-
if (maxSpeed < avoidSpeedLimit)
567-
{
568-
weightToPrioMap.put(40d, PREFER.getValue());
569-
if (way.hasTag("tunnel", intendedValues))
570-
weightToPrioMap.put(40d, UNCHANGED.getValue());
571-
}
572-
} else
573-
{
574-
if (avoidHighwayTags.contains(highway)
575-
|| maxSpeed >= avoidSpeedLimit && !"track".equals(highway))
576-
{
577-
weightToPrioMap.put(50d, REACH_DEST.getValue());
578-
if (way.hasTag("tunnel", intendedValues))
579-
weightToPrioMap.put(50d, AVOID_AT_ALL_COSTS.getValue());
580-
}
581-
}
582-
583-
if (pushingSections.contains(highway)
584-
|| way.hasTag("bicycle", "use_sidepath")
585-
|| "parking_aisle".equals(service))
586-
{
587-
if (way.hasTag("bicycle", "yes"))
588-
weightToPrioMap.put(100d, UNCHANGED.getValue());
589-
else
590-
weightToPrioMap.put(50d, AVOID_IF_POSSIBLE.getValue());
591-
}
592-
593-
if (way.hasTag("railway", "tram"))
594-
weightToPrioMap.put(50d, AVOID_AT_ALL_COSTS.getValue());
595-
596-
String classBicycleSpecific = way.getTag(specificBicycleClass);
597-
if (classBicycleSpecific != null)
598-
{
599-
// We assume that humans are better in classifying preferences compared to our algorithm above -> weight = 100
600-
weightToPrioMap.put(100d, convertCallValueToPriority(classBicycleSpecific).getValue());
601-
} else
602-
{
603-
String classBicycle = way.getTag("class:bicycle");
604-
if (classBicycle != null)
605-
weightToPrioMap.put(100d, convertCallValueToPriority(classBicycle).getValue());
606-
}
607-
}
608479

609480
/**
610481
* Handle surface and wayType encoding

0 commit comments

Comments
 (0)