noSidewalkValues = new HashSet<>(5);
+
+ protected EncodedValue priorityWayEncoder;
+ protected EncodedValue relationCodeEncoder;
+
+ FootFlagEncoder(int speedBits, double speedFactor) {
+ super(speedBits, speedFactor, 0);
+ restrictions.addAll(Arrays.asList("foot", "access"));
+
+ restrictedValues.addAll(Arrays.asList(
+ "private",
+ "no",
+ "restricted",
+ "military",
+ "emergency"
+ ));
+
+ intendedValues.addAll(Arrays.asList(
+ "yes",
+ "designated",
+ "official",
+ "permissive"
+ ));
+
+ noSidewalkValues.addAll(Arrays.asList(
+ "no",
+ "none",
+ "separate",
+ "separate"
+ ));
+
+ usableSidewalkValues.addAll(Arrays.asList(
+ "yes",
+ "both",
+ "left",
+ "right"
+ ));
+
+ setBlockByDefault(false);
+ potentialBarriers.add("gate");
+
+ safeHighwayTags.addAll(Arrays.asList(
+ "footway",
+ "path",
+ "steps",
+ "pedestrian",
+ "living_street",
+ "track",
+ "residential",
+ "service"
+ ));
+
+ avoidHighwayTags.addAll(Arrays.asList(
+ "secondary",
+ "secondary_link",
+ "tertiary",
+ "tertiary_link"
+ ));
+
+ avoidUnlessSidewalkTags.addAll(Arrays.asList(
+ "trunk",
+ "trunk_link",
+ "primary",
+ "primary_link"
+ ));
+
+ allowedHighwayTags.addAll(safeHighwayTags);
+ allowedHighwayTags.addAll(avoidHighwayTags);
+ allowedHighwayTags.addAll(avoidUnlessSidewalkTags);
+ allowedHighwayTags.addAll(Arrays.asList(
+ "cycleway",
+ "unclassified",
+ "road"
+ ));
+
+ hikingNetworkToCode.put("iwn", UNCHANGED.getValue());
+ hikingNetworkToCode.put("nwn", UNCHANGED.getValue());
+ hikingNetworkToCode.put("rwn", UNCHANGED.getValue());
+ hikingNetworkToCode.put("lwn", UNCHANGED.getValue());
+
+ maxPossibleSpeed = FERRY_SPEED;
+
+ init();
+ }
+
+ public double getMeanSpeed() {
+ return MEAN_SPEED;
+ }
+
+ @Override
+ public int defineWayBits(int index, int shift) {
+ // first two bits are reserved for route handling in superclass
+ shift = super.defineWayBits(index, shift);
+ // larger value required - ferries are faster than pedestrians
+ speedEncoder = new EncodedDoubleValue("Speed", shift, speedBits, speedFactor, MEAN_SPEED, maxPossibleSpeed);
+ shift += speedEncoder.getBits();
+
+ priorityWayEncoder = new EncodedValue("PreferWay", shift, 3, 1, 0, 7);
+ shift += priorityWayEncoder.getBits();
+ return shift;
+ }
+
+ @Override
+ public int defineRelationBits(int index, int shift) {
+ relationCodeEncoder = new EncodedValue("RelationCode", shift, 3, 1, 0, 7);
+ return shift + relationCodeEncoder.getBits();
+ }
+
+ /**
+ * Foot flag encoder does not provide any turn cost / restrictions
+ */
+ @Override
+ public int defineTurnBits(int index, int shift) {
+ return shift;
+ }
+
+ /**
+ * Foot flag encoder does not provide any turn cost / restrictions
+ *
+ *
+ * @return false
+ */
+ @Override
+ public boolean isTurnRestricted(long flag) {
+ return false;
+ }
+
+ /**
+ * Foot flag encoder does not provide any turn cost / restrictions
+ *
+ *
+ * @return 0
+ */
+ @Override
+ public double getTurnCost(long flag) {
+ return 0;
+ }
+
+ @Override
+ public long getTurnFlags(boolean restricted, double costs) {
+ return 0;
+ }
+
+ @Override
+ public long handleRelationTags(ReaderRelation relation, long oldRelationFlags) {
+ int code = 0;
+ if (relation.hasTag(OSMTags.Keys.ROUTE, "hiking") || relation.hasTag(OSMTags.Keys.ROUTE, "foot")) {
+ Integer val = hikingNetworkToCode.get(relation.getTag("network"));
+ if (val != null)
+ code = val;
+ else
+ code = hikingNetworkToCode.get("lwn");
+ } else if (relation.hasTag(OSMTags.Keys.ROUTE, "ferry")) {
+ code = PriorityCode.AVOID_IF_POSSIBLE.getValue();
+ }
+
+ int oldCode = (int) relationCodeEncoder.getValue(oldRelationFlags);
+ if (oldCode < code)
+ return relationCodeEncoder.setValue(0, code);
+ return oldRelationFlags;
+ }
+
+ @Override
+ public long handleWayTags(ReaderWay way, long allowed, long relationFlags) {
+ if (!isAccept(allowed))
+ return 0;
+
+ long flags = 0;
+ if (!isFerry(allowed)) {
+ String sacScale = way.getTag(OSMTags.Keys.SAC_SCALE);
+ if (sacScale != null && !"hiking".equals(sacScale)) {
+ flags = speedEncoder.setDoubleValue(flags, SLOW_SPEED);
+ } else {
+ flags = speedEncoder.setDoubleValue(flags, MEAN_SPEED);
+ }
+ flags |= directionBitMask;
+
+ boolean isRoundabout = way.hasTag(OSMTags.Keys.JUNCTION, "roundabout") || way.hasTag(OSMTags.Keys.JUNCTION, "circular");
+ if (isRoundabout)
+ flags = setBool(flags, K_ROUNDABOUT, true);
+
+ } else {
+ double ferrySpeed = getFerrySpeed(way);
+ flags = setSpeed(flags, ferrySpeed);
+ flags |= directionBitMask;
+ }
+
+ int priorityFromRelation = 0;
+ if (relationFlags != 0)
+ priorityFromRelation = (int) relationCodeEncoder.getValue(relationFlags);
+
+ flags = priorityWayEncoder.setValue(flags, handlePriority(way, priorityFromRelation));
+
+ return flags;
+ }
+
+ @Override
+ public double getDouble(long flags, int key) {
+ if (key == PriorityWeighting.KEY)
+ return (double) priorityWayEncoder.getValue(flags) / BEST.getValue();
+ else
+ return super.getDouble(flags, key);
+ }
+
+ @Override
+ public long acceptWay(ReaderWay way) {
+ String highwayValue = way.getTag(OSMTags.Keys.HIGHWAY);
+
+ if (highwayValue == null)
+ return handleNonHighways(way);
+
+ if (hasTooDifficultSacScale(way))
+ return 0;
+
+ // no need to evaluate ferries or fords - already included here
+ if (way.hasTag(OSMTags.Keys.FOOT, intendedValues))
+ return acceptBit;
+
+ // check access restrictions
+ if (way.hasTag(restrictions, restrictedValues) && !getConditionalTagInspector().isRestrictedWayConditionallyPermitted(way))
+ return 0;
+
+ if (way.hasTag(OSMTags.Keys.SIDEWALK, usableSidewalkValues))
+ return acceptBit;
+
+ if (!allowedHighwayTags.contains(highwayValue))
+ return 0;
+
+ if (way.hasTag(OSMTags.Keys.MOTOR_ROAD, "yes"))
+ return 0;
+
+ // do not get our feet wet, "yes" is already included above
+ if (isBlockFords() && (way.hasTag(OSMTags.Keys.HIGHWAY, "ford") || way.hasTag(OSMTags.Keys.FORD)))
+ return 0;
+
+ if (getConditionalTagInspector().isPermittedWayConditionallyRestricted(way))
+ return 0;
+
+ return acceptBit;
+ }
+
+ /**
+ * Method which generates the acceptance flag for ways that are not seen as being highways (such as ferry routes)
+ *
+ * @param way The way that is to be assessed
+ * @return The acceptance flag for the way
+ */
+ private long handleNonHighways(ReaderWay way) {
+ long acceptPotentially = 0;
+
+ if (way.hasTag(OSMTags.Keys.ROUTE, ferries)) {
+ String footTag = way.getTag(OSMTags.Keys.FOOT);
+ if (footTag == null || "yes".equals(footTag))
+ acceptPotentially = acceptBit | ferryBit;
+ }
+
+ // special case not for all acceptedRailways, only platform
+ if (way.hasTag(OSMTags.Keys.RAILWAY, "platform"))
+ acceptPotentially = acceptBit;
+
+ if (way.hasTag(OSMTags.Keys.MAN_MADE, "pier"))
+ acceptPotentially = acceptBit;
+
+ if (acceptPotentially != 0) {
+ if (way.hasTag(restrictions, restrictedValues) && !getConditionalTagInspector().isRestrictedWayConditionallyPermitted(way))
+ return 0;
+ return acceptPotentially;
+ }
+
+ return 0;
+ }
+
+ /**
+ * Determine if the way is seen as being too difficult based on any sac_scale tags and the information provided in
+ * the setup of the object (suitableSacScales)
+ *
+ * @param way The way to be assessed
+ * @return Whether the way is too difficult or not
+ */
+ private boolean hasTooDifficultSacScale(ReaderWay way) {
+ String sacScale = way.getTag(OSMTags.Keys.SAC_SCALE);
+ return sacScale != null && !suitableSacScales.contains(sacScale);
+ }
+
+ /**
+ * Assign priorities based on relations and values stored against the way. This is the top level method that calls
+ * other priority assessment methods
+ *
+ * @param way The way to be assessed
+ * @param priorityFromRelation The priority obtained from any relations
+ * @return The overall priority value for the way
+ */
+ private int handlePriority(ReaderWay way, int priorityFromRelation) {
+ TreeMap weightToPrioMap = new TreeMap<>();
+ if (priorityFromRelation == 0)
+ weightToPrioMap.put(0d, UNCHANGED.getValue());
+ else
+ weightToPrioMap.put(110d, priorityFromRelation);
+
+ assignPriorities(way, weightToPrioMap);
+
+ // pick priority with biggest order value
+ return weightToPrioMap.lastEntry().getValue();
+ }
+
+ /**
+ * @param weightToPrioMap associate a weight with every priority. This sorted map allows
+ * subclasses to 'insert' more important priorities as well as overwrite determined priorities.
+ */
+ private void assignPriorities(ReaderWay way, TreeMap weightToPrioMap) {
+ if (way.hasTag(OSMTags.Keys.FOOT, "designated"))
+ weightToPrioMap.put(100d, PREFER.getValue());
+
+ assignSafeHighwayPriority(way, weightToPrioMap);
+
+ assignAvoidHighwayPriority(way, weightToPrioMap);
+
+ assignAvoidUnlessSidewalkPresentPriority(way, weightToPrioMap);
+
+ assignBicycleWayPriority(way, weightToPrioMap);
+
+ }
+
+ /**
+ * Update the weight priority map based on values relating to highway types that are identified as being "safe" or
+ * with low speeds
+ *
+ * @param way The way containing the tag information
+ * @param weightToPrioMap The priority weight map that will have the weightings updated
+ */
+ void assignSafeHighwayPriority(ReaderWay way, TreeMap weightToPrioMap) {
+ String highway = way.getTag(OSMTags.Keys.HIGHWAY);
+ double maxSpeed = getMaxSpeed(way);
+
+ if (safeHighwayTags.contains(highway) || maxSpeed > 0 && maxSpeed <= 20) {
+ if (preferredWayTags.contains(highway))
+ weightToPrioMap.put(40d, VERY_NICE.getValue());
+ else {
+ weightToPrioMap.put(40d, PREFER.getValue());
+ }
+ assignTunnelPriority(way, weightToPrioMap);
+ }
+ }
+
+ /**
+ * Update the weight priority map based on tunnel information
+ *
+ * @param way The way containing the tag information
+ * @param weightToPrioMap The priority weight map that will have the weightings updated
+ */
+ void assignTunnelPriority(ReaderWay way, TreeMap weightToPrioMap) {
+ if (way.hasTag(OSMTags.Keys.TUNNEL, intendedValues)) {
+ if (way.hasTag(OSMTags.Keys.SIDEWALK, noSidewalkValues))
+ weightToPrioMap.put(40d, AVOID_IF_POSSIBLE.getValue());
+ else
+ weightToPrioMap.put(40d, UNCHANGED.getValue());
+ }
+ }
+
+ /**
+ * Update the weight priority map based on values relating to avoiding highways
+ *
+ * @param way The way containing the tag information
+ * @param weightToPrioMap The priority weight map that will have the weightings updated
+ */
+ private void assignAvoidHighwayPriority(ReaderWay way, TreeMap weightToPrioMap) {
+ String highway = way.getTag(OSMTags.Keys.HIGHWAY);
+ double maxSpeed = getMaxSpeed(way);
+
+ if ((maxSpeed > 50 || avoidHighwayTags.contains(highway))
+ && !way.hasTag(OSMTags.Keys.SIDEWALK, usableSidewalkValues)) {
+ weightToPrioMap.put(45d, REACH_DEST.getValue());
+ }
+ }
+
+ /**
+ * Mark the way as to be avoided if there is no sidewalk present on highway types identified as needing a sidewalk
+ * to be traversed
+ *
+ * @param way The way containing the tag information
+ * @param weightToPrioMap The priority weight map that will have the weightings updated
+ */
+ private void assignAvoidUnlessSidewalkPresentPriority(ReaderWay way, TreeMap weightToPrioMap) {
+ String highway = way.getTag(OSMTags.Keys.HIGHWAY);
+ if (avoidUnlessSidewalkTags.contains(highway) && !way.hasTag(OSMTags.Keys.SIDEWALK, usableSidewalkValues))
+ weightToPrioMap.put(45d, AVOID_AT_ALL_COSTS.getValue());
+ }
+
+ /**
+ * Update the weight priority map based on values relating to bicycle ways.
+ *
+ * @param way The way containing the tag information
+ * @param weightToPrioMap The priority weight map that will have the weightings updated
+ */
+ private void assignBicycleWayPriority(ReaderWay way, TreeMap weightToPrioMap) {
+ if (way.hasTag(OSMTags.Keys.BICYCLE, "official") || way.hasTag(OSMTags.Keys.BICYCLE, "designated"))
+ weightToPrioMap.put(44d, AVOID_IF_POSSIBLE.getValue());
+ }
+
+ @Override
+ public boolean supports(Class> feature) {
+ if (super.supports(feature)) {
+ return true;
+ }
+
+ return PriorityWeighting.class.isAssignableFrom(feature);
+ }
+
+ /*
+ * This method is a current hack, to allow ferries to be actually faster than our current storable maxSpeed.
+ */
+ @Override
+ public double getSpeed(long flags) {
+ double speed = super.getSpeed(flags);
+ if (speed == getMaxSpeed()) {
+ // We cannot be sure if it was a long or a short trip
+ return SHORT_TRIP_FERRY_SPEED;
+ }
+
+ return speed;
+ }
+}
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/HeavyVehicleFlagEncoder.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/HeavyVehicleFlagEncoder.java
index f9e154dfb1..188737d808 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/HeavyVehicleFlagEncoder.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/HeavyVehicleFlagEncoder.java
@@ -27,7 +27,7 @@
import static com.graphhopper.routing.util.PriorityCode.BEST;
import static com.graphhopper.routing.util.PriorityCode.UNCHANGED;
-public class HeavyVehicleFlagEncoder extends ORSAbstractFlagEncoder
+public class HeavyVehicleFlagEncoder extends VehicleFlagEncoder
{
protected final HashSet forwardKeys = new HashSet(5);
protected final HashSet backwardKeys = new HashSet(5);
@@ -37,6 +37,7 @@ public class HeavyVehicleFlagEncoder extends ORSAbstractFlagEncoder
protected boolean useAcceleration = false;
protected int maxTrackGradeLevel = 3;
+ private static final int MEAN_SPEED = 70;
/**
* A map which associates string to speed. Get some impression:
@@ -186,6 +187,10 @@ public HeavyVehicleFlagEncoder( int speedBits, double speedFactor, int maxTurnCo
init();
}
+
+ public double getMeanSpeed() {
+ return MEAN_SPEED;
+ }
public double getDefaultMaxSpeed()
{
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/HikingFlagEncoder.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/HikingFlagEncoder.java
new file mode 100644
index 0000000000..883a3254fc
--- /dev/null
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/HikingFlagEncoder.java
@@ -0,0 +1,66 @@
+/*
+ * This file is part of Openrouteservice.
+ *
+ * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with this library;
+ * if not, see .
+ */
+
+package heigit.ors.routing.graphhopper.extensions.flagencoders;
+
+import com.graphhopper.util.PMap;
+
+import java.util.Arrays;
+
+import static com.graphhopper.routing.util.PriorityCode.BEST;
+import static com.graphhopper.routing.util.PriorityCode.VERY_NICE;
+
+public class HikingFlagEncoder extends FootFlagEncoder {
+ public HikingFlagEncoder(PMap properties) {
+ this((int) properties.getLong("speedBits", 4),
+ properties.getDouble("speedFactor", 1));
+ this.properties = properties;
+ this.setBlockFords(properties.getBool("block_fords", false));
+ }
+
+ private HikingFlagEncoder(int speedBits, double speedFactor) {
+ super(speedBits, speedFactor);
+
+ hikingNetworkToCode.put("iwn", BEST.getValue());
+ hikingNetworkToCode.put("nwn", BEST.getValue());
+ hikingNetworkToCode.put("rwn", VERY_NICE.getValue());
+ hikingNetworkToCode.put("lwn", VERY_NICE.getValue());
+
+ suitableSacScales.addAll(Arrays.asList(
+ "hiking",
+ "mountain_hiking",
+ "demanding_mountain_hiking",
+ "alpine_hiking"
+ ));
+
+ preferredWayTags.addAll(Arrays.asList(
+ "track",
+ "path",
+ "footway"
+ ));
+
+ init();
+ }
+
+ @Override
+ public int getVersion() {
+ return 3;
+ }
+
+ @Override
+ public String toString() {
+ return FlagEncoderNames.HIKING_ORS;
+ }
+}
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/ORSAbstractFlagEncoder.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/ORSAbstractFlagEncoder.java
index e790d964ae..1cd92adb89 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/ORSAbstractFlagEncoder.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/ORSAbstractFlagEncoder.java
@@ -15,199 +15,176 @@
import com.graphhopper.reader.ReaderWay;
import com.graphhopper.routing.util.AbstractFlagEncoder;
+import com.graphhopper.routing.util.EncodedDoubleValue;
+import com.graphhopper.util.BitUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public abstract class ORSAbstractFlagEncoder extends AbstractFlagEncoder {
+ private final static Logger logger = LoggerFactory.getLogger(ORSAbstractFlagEncoder.class);
- private final double ACCELERATION_SPEED_CUTOFF_MAX = 80.0;
- private final double ACCELERATION_SPEED_CUTOFF_MIN = 20.0;
- protected SpeedLimitHandler _speedLimitHandler;
-
- private double accelerationModifier = 0.0;
+ protected boolean considerElevation = false;
+ protected EncodedDoubleValue reverseSpeedEncoder;
+ protected boolean blockByDefault = true;
protected ORSAbstractFlagEncoder(int speedBits, double speedFactor, int maxTurnCosts) {
super(speedBits, speedFactor, maxTurnCosts);
}
- double addResedentialPenalty(double baseSpeed, ReaderWay way) {
- if (baseSpeed == 0)
- return 0;
- double speed = baseSpeed;
-
- if(way.hasTag("highway","residential")) {
- double estDist = way.getTag("estimated_distance", Double.MAX_VALUE);
- // take into account number of nodes to get an average distance between nodes
- double interimDistance = estDist;
- int interimNodes = way.getNodes().size() - 2;
- if(interimNodes > 0) {
- interimDistance = estDist/(interimNodes+1);
- }
- if(interimDistance < 100) {
- speed = speed * 0.5;
- }
- //Don't go below 2.5 because it will be stored as 0 later
- if(speed < 5)
- speed = 5;
- }
-
- return speed;
+ public void setConsiderElevation(boolean considerElevation) {
+ this.considerElevation = considerElevation;
}
- double averageSecondsTo100KmpH() { return 10; }
-
- /**
- * Returns how many seconds it is assumed that this vehicle would reach 100 km/h taking into acocunt the acceleration modifier
- *
- * @return
- */
- double secondsTo100KmpH() {
- return averageSecondsTo100KmpH() + (accelerationModifier * averageSecondsTo100KmpH());
- }
-
- /**
- * Returns the acceleration in KM per hour per second.
- *
- * @return
- */
- double accelerationKmpHpS() {
- return 100.0 / secondsTo100KmpH();
- }
-
- /**
- * Adjust the maximum speed taking into account supposed acceleration on the segment. The method looks at acceleration
- * along the way (assuming starting from 0km/h) and then uses the length to travel and the supposed maximum speed
- * to determine an average speed for travelling along the whole segment.
- *
- * @param distance How long the segment to travel along is
- * @param maximumSpeedInKmph The maximum speed that a vehicle can travel along this segment (usually the speed limit)
- * @return
- */
- double adjustSpeedForAcceleration(double distance, double maximumSpeedInKmph) {
- // We only want to perform the adjustment if the road is a slower speed - main roads shouldnt be affected as much due to less junctions and changes in direction
- if(maximumSpeedInKmph < ACCELERATION_SPEED_CUTOFF_MAX) {
- if (distance <= 0) {
- return maximumSpeedInKmph;
- }
-
- // slower roads can be assumed to have slower acceleration...
-
- double normalisedSpeed = maximumSpeedInKmph;
- if(normalisedSpeed < ACCELERATION_SPEED_CUTOFF_MIN)
- normalisedSpeed = ACCELERATION_SPEED_CUTOFF_MIN;
+ public abstract double getMeanSpeed();
- normalisedSpeed = (normalisedSpeed -ACCELERATION_SPEED_CUTOFF_MIN) / (ACCELERATION_SPEED_CUTOFF_MAX-ACCELERATION_SPEED_CUTOFF_MIN);
-
- accelerationModifier = Math.pow(0.01, normalisedSpeed);
-
- double timeToMaxSpeed = durationToMaxSpeed(0, maximumSpeedInKmph);
-
- // We need to calculate how much distance is travelled in acceleration/deceleration phases
- double accelerationDistance = distanceTravelledInDuration(0, maximumSpeedInKmph, timeToMaxSpeed);
-
- double distanceAtMaxSpeed = distance - (accelerationDistance * 2); // Double the distance because of deceleration aswell
-
- double averageSpeed;
+ @Override
+ public long reverseFlags(long flags) {
+ flags = super.reverseFlags(flags);
+ if (considerElevation) {
+ // swap speeds
+ double temp = reverseSpeedEncoder.getDoubleValue(flags);
+ flags = setReverseSpeed(flags, speedEncoder.getDoubleValue(flags));
+ flags = setSpeed(flags, temp);
+ }
+ return flags;
+ }
- if (distanceAtMaxSpeed < 0) {
- averageSpeed = convertMpsToKmph(distance / (durationToTravelDistance(0, maximumSpeedInKmph, distance / 2) * 2));
+ @Override
+ protected long setLowSpeed(long flags, double speed, boolean reverse) {
+ if (considerElevation) {
+ if (reverse) {
+ return setBool(reverseSpeedEncoder.setDoubleValue(flags, 0), K_BACKWARD, false);
} else {
- double timeAtMaxSpeed = distanceAtMaxSpeed / convertKmphToMps(maximumSpeedInKmph);
- double averageSpeedMps = distance / (timeToMaxSpeed*2 + timeAtMaxSpeed);
-
- averageSpeed = convertMpsToKmph(averageSpeedMps);
+ return setBool(speedEncoder.setDoubleValue(flags, 0), K_FORWARD, false);
}
-
- return averageSpeed;
- } else {
- return maximumSpeedInKmph;
}
+ return super.setLowSpeed(flags, speed, reverse);
}
- /**
- * How many seconds does it take to reach maximum speed based on initial speed and acceleration.
- *
- * @param initialSpeedInKmph How fast the vehicle is travelling at the start of the calculation
- * @param maxSpeedInKmph The target speed to be reached
- * @return How long it takes to reach the speed in seconds
- */
- private double durationToMaxSpeed(double initialSpeedInKmph, double maxSpeedInKmph) {
- return (maxSpeedInKmph - initialSpeedInKmph) / accelerationKmpHpS();
+ @Override
+ public long flagsDefault(boolean forward, boolean backward) {
+ long flags = super.flagsDefault(forward, backward);
+ if (considerElevation && backward) {
+ flags = reverseSpeedEncoder.setDefaultValue(flags);
+ }
+ return flags;
}
- /**
- * How long in seconds does it take to reach the intended distance based on the initial travelling speed and the
- * maximum speed that can be travelled.
- *
- * @param initialSpeedInKmph The speed of the vehicle when starting the calculation
- * @param maxSpeedInKmph The maximum speed the vehicle can travel at
- * @param distanceInM The target distance to be travelled
- * @return How long it takes in seconds to reach the target distance
- */
- private double durationToTravelDistance(double initialSpeedInKmph, double maxSpeedInKmph, double distanceInM) {
- double secondsTravelled = 0;
- double distanceTravelled = 0;
-
- double currentSpeed = initialSpeedInKmph;
-
- while(currentSpeed < maxSpeedInKmph && distanceTravelled < distanceInM) {
- currentSpeed += accelerationKmpHpS();
- secondsTravelled += 1;
- distanceTravelled += convertKmphToMps(currentSpeed);
+ @Override
+ public long setReverseSpeed(long flags, double speed) {
+ if (considerElevation) {
+ // taken from GH Bike2WeightFlagEncoder.setReverseSpeed(...)
+ if (speed < 0 || Double.isNaN(speed)) {
+ throw new IllegalArgumentException("Speed cannot be negative: " + speed + ", flags:" + BitUtil.LITTLE.toBitString(flags));
+ }
+ if (speed < speedEncoder.getFactor() / 2) {
+ return setLowSpeed(flags, speed, true);
+ }
+ if (speed > getMaxSpeed()) {
+ speed = getMaxSpeed();
+ }
+ return reverseSpeedEncoder.setDoubleValue(flags, speed);
+ } else {
+ return setSpeed(flags, speed);
}
+ }
- double distanceRemaining = distanceInM - distanceTravelled;
+ @Override
+ public double getReverseSpeed(long flags) {
+ if (considerElevation) {
+ return reverseSpeedEncoder.getDoubleValue(flags);
+ }
+ return getSpeed(flags);
+ }
- if(distanceRemaining > 0) {
- secondsTravelled += (distanceRemaining / convertKmphToMps(maxSpeedInKmph));
+ @Override
+ public long setProperties(double speed, boolean forward, boolean backward) {
+ long flags = super.setAccess(setSpeed(0, speed), forward, backward);
+ if (considerElevation && backward) {
+ flags = setReverseSpeed(flags, speed);
}
+ return flags;
+ }
- return secondsTravelled;
+ @Override
+ public double getMaxSpeed(ReaderWay way) {
+ return super.getMaxSpeed(way);
}
- /**
- * How far can the vehicle travel in the specified time frame
- *
- * @param initialSpeedInKmph The starting speed of the vehicle
- * @param maxSpeedInKmph The maximum travel speed
- * @param duration How long is the vehicle travelling for
- * @return The distance in metres that the vehicle travels in the specified time
- */
- private double distanceTravelledInDuration(double initialSpeedInKmph, double maxSpeedInKmph, double duration) {
- double secondsTravelled = 0;
- double distanceTravelled = 0;
- double currentSpeed = initialSpeedInKmph;
-
- while(currentSpeed < maxSpeedInKmph && secondsTravelled < duration) {
- currentSpeed += accelerationKmpHpS();
- secondsTravelled += 1;
- distanceTravelled += convertKmphToMps(currentSpeed);
- }
+ @Override
+ protected double getFerrySpeed(ReaderWay way) {
+ return getFerrySpeed(way, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
+ }
- double secondsRemaining = duration - secondsTravelled;
+ protected double getFerrySpeed(ReaderWay way, double unknownSpeed, double shortTripsSpeed, double longTripsSpeed) {
+ // taken from GH AbstractFlagEncoder.getFerrySpeed(...),
+ long duration = 0;
- if(secondsRemaining > 0 ) {
- distanceTravelled += (secondsRemaining * convertKmphToMps(maxSpeedInKmph));
+ try {
+ // During the reader process we have converted the duration value into a artificial tag called "duration:seconds".
+ duration = Long.parseLong(way.getTag("duration:seconds"));
+ } catch (Exception ex) {
}
+ // seconds to hours
+ double durationInHours = duration / 60d / 60d;
+ // Check if our graphhopper specific artificially created estimated_distance way tag is present
+ Number estimatedLength = way.getTag("estimated_distance", null);
+ if (durationInHours > 0)
+ try {
+ if (estimatedLength != null) {
+ double estimatedLengthInKm = estimatedLength.doubleValue() / 1000;
+ // If duration AND distance is available we can calculate the speed more precisely
+ // and set both speed to the same value. Factor 1.4 slower because of waiting time!
+ double calculatedTripSpeed = estimatedLengthInKm / durationInHours / 1.4;
+ // Plausibility check especially for the case of wrongly used PxM format with the intention to
+ // specify the duration in minutes, but actually using months
+ if (calculatedTripSpeed > 0.01d) {
+ if (calculatedTripSpeed > getMaxSpeed()) {
+ return getMaxSpeed();
+ }
+ // If the speed is lower than the speed we can store, we have to set it to the minSpeed, but > 0
+ if (Math.round(calculatedTripSpeed) < speedEncoder.getFactor() / 2) {
+ return speedEncoder.getFactor() / 2;
+ }
+
+ return Math.round(calculatedTripSpeed);
+ } else {
+ long lastId = way.getNodes().isEmpty() ? -1 : way.getNodes().get(way.getNodes().size() - 1);
+ long firstId = way.getNodes().isEmpty() ? -1 : way.getNodes().get(0);
+ if (firstId != lastId)
+ logger.warn("Unrealistic long duration ignored in way with way ID=" + way.getId() + " : Duration tag value="
+ + way.getTag("duration") + " (=" + Math.round(duration / 60d) + " minutes)");
+ durationInHours = 0;
+ }
+ }
+ } catch (Exception ex) {
+ }
- return distanceTravelled;
+ if (durationInHours == 0) {
+ if(estimatedLength != null && estimatedLength.doubleValue() <= 300)
+ return speedEncoder.getFactor() / 2;
+ if(Integer.MIN_VALUE == unknownSpeed)
+ return UNKNOWN_DURATION_FERRY_SPEED;
+ return unknownSpeed;
+ } else if (durationInHours > 1) {
+ // lengthy ferries should be faster than short trip ferry
+ if(Integer.MIN_VALUE == longTripsSpeed)
+ return LONG_TRIP_FERRY_SPEED;
+ return longTripsSpeed;
+ } else {
+ if(Integer.MIN_VALUE == shortTripsSpeed)
+ return SHORT_TRIP_FERRY_SPEED;
+ return shortTripsSpeed;
+ }
}
- /**
- * Convert kilometres per hour to metres per second
- *
- * @param speedInKmph The speed to be converted in km per hour
- * @return The speed in metres per second
- */
- private double convertKmphToMps(double speedInKmph) {
- return (speedInKmph * 1000) / 3600;
+ @Override
+ public void setBlockByDefault(boolean blockByDefault) {
+ super.setBlockByDefault(blockByDefault);
+ this.blockByDefault = blockByDefault;
}
- /**
- * Convert metres per second to kilometres per hour
- *
- * @param speedInMps The speed in metres per second
- * @return The speed in kilometres per hour
- */
- private double convertMpsToKmph(double speedInMps) {
- return (3600 * speedInMps) / 1000;
+ public boolean isBlockByDefault() {
+ return this.blockByDefault;
}
}
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/PedestrianFlagEncoder.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/PedestrianFlagEncoder.java
new file mode 100644
index 0000000000..24f24d2c72
--- /dev/null
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/PedestrianFlagEncoder.java
@@ -0,0 +1,47 @@
+/*
+ * This file is part of Openrouteservice.
+ *
+ * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with this library;
+ * if not, see .
+ */
+
+package heigit.ors.routing.graphhopper.extensions.flagencoders;
+
+import com.graphhopper.util.PMap;
+
+public class PedestrianFlagEncoder extends FootFlagEncoder {
+
+ public PedestrianFlagEncoder(PMap properties) {
+ this((int) properties.getLong("speedBits", 4),
+ properties.getDouble("speedFactor", 1));
+ this.properties = properties;
+ this.setBlockFords(properties.getBool("block_fords", true));
+ }
+
+ private PedestrianFlagEncoder(int speedBits, double speedFactor) {
+ super(speedBits, speedFactor);
+
+ suitableSacScales.add("hiking");
+
+ init();
+ }
+
+ @Override
+
+ public int getVersion() {
+ return 4;
+ }
+
+ @Override
+ public String toString() {
+ return FlagEncoderNames.PEDESTRIAN_ORS;
+ }
+}
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/VehicleFlagEncoder.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/VehicleFlagEncoder.java
new file mode 100644
index 0000000000..9c1ad08236
--- /dev/null
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/VehicleFlagEncoder.java
@@ -0,0 +1,213 @@
+/*
+ * This file is part of Openrouteservice.
+ *
+ * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with this library;
+ * if not, see .
+ */
+
+package heigit.ors.routing.graphhopper.extensions.flagencoders;
+
+import com.graphhopper.reader.ReaderWay;
+
+public abstract class VehicleFlagEncoder extends ORSAbstractFlagEncoder {
+ private final double ACCELERATION_SPEED_CUTOFF_MAX = 80.0;
+ private final double ACCELERATION_SPEED_CUTOFF_MIN = 20.0;
+ protected SpeedLimitHandler _speedLimitHandler;
+
+ private double accelerationModifier = 0.0;
+
+ VehicleFlagEncoder(int speedBits, double speedFactor, int maxTurnCosts) {
+ super(speedBits, speedFactor, maxTurnCosts);
+ }
+
+ double addResedentialPenalty(double baseSpeed, ReaderWay way) {
+ if (baseSpeed == 0)
+ return 0;
+ double speed = baseSpeed;
+
+ if(way.hasTag("highway","residential")) {
+ double estDist = way.getTag("estimated_distance", Double.MAX_VALUE);
+ // take into account number of nodes to get an average distance between nodes
+ double interimDistance = estDist;
+ int interimNodes = way.getNodes().size() - 2;
+ if(interimNodes > 0) {
+ interimDistance = estDist/(interimNodes+1);
+ }
+ if(interimDistance < 100) {
+ speed = speed * 0.5;
+ }
+ //Don't go below 2.5 because it will be stored as 0 later
+ if(speed < 5)
+ speed = 5;
+ }
+
+ return speed;
+ }
+
+ double averageSecondsTo100KmpH() { return 10; }
+
+ /**
+ * Returns how many seconds it is assumed that this vehicle would reach 100 km/h taking into acocunt the acceleration modifier
+ *
+ * @return
+ */
+ double secondsTo100KmpH() {
+ return averageSecondsTo100KmpH() + (accelerationModifier * averageSecondsTo100KmpH());
+ }
+
+ /**
+ * Returns the acceleration in KM per hour per second.
+ *
+ * @return
+ */
+ double accelerationKmpHpS() {
+ return 100.0 / secondsTo100KmpH();
+ }
+
+ /**
+ * Adjust the maximum speed taking into account supposed acceleration on the segment. The method looks at acceleration
+ * along the way (assuming starting from 0km/h) and then uses the length to travel and the supposed maximum speed
+ * to determine an average speed for travelling along the whole segment.
+ *
+ * @param distance How long the segment to travel along is
+ * @param maximumSpeedInKmph The maximum speed that a vehicle can travel along this segment (usually the speed limit)
+ * @return
+ */
+ double adjustSpeedForAcceleration(double distance, double maximumSpeedInKmph) {
+ // We only want to perform the adjustment if the road is a slower speed - main roads shouldnt be affected as much due to less junctions and changes in direction
+ if(maximumSpeedInKmph < ACCELERATION_SPEED_CUTOFF_MAX) {
+ if (distance <= 0) {
+ return maximumSpeedInKmph;
+ }
+
+ // slower roads can be assumed to have slower acceleration...
+
+ double normalisedSpeed = maximumSpeedInKmph;
+ if(normalisedSpeed < ACCELERATION_SPEED_CUTOFF_MIN)
+ normalisedSpeed = ACCELERATION_SPEED_CUTOFF_MIN;
+
+ normalisedSpeed = (normalisedSpeed -ACCELERATION_SPEED_CUTOFF_MIN) / (ACCELERATION_SPEED_CUTOFF_MAX-ACCELERATION_SPEED_CUTOFF_MIN);
+
+ accelerationModifier = Math.pow(0.01, normalisedSpeed);
+
+ double timeToMaxSpeed = durationToMaxSpeed(0, maximumSpeedInKmph);
+
+ // We need to calculate how much distance is travelled in acceleration/deceleration phases
+ double accelerationDistance = distanceTravelledInDuration(0, maximumSpeedInKmph, timeToMaxSpeed);
+
+ double distanceAtMaxSpeed = distance - (accelerationDistance * 2); // Double the distance because of deceleration aswell
+
+ double averageSpeed;
+
+ if (distanceAtMaxSpeed < 0) {
+ averageSpeed = convertMpsToKmph(distance / (durationToTravelDistance(0, maximumSpeedInKmph, distance / 2) * 2));
+ } else {
+ double timeAtMaxSpeed = distanceAtMaxSpeed / convertKmphToMps(maximumSpeedInKmph);
+ double averageSpeedMps = distance / (timeToMaxSpeed*2 + timeAtMaxSpeed);
+
+ averageSpeed = convertMpsToKmph(averageSpeedMps);
+ }
+
+ return averageSpeed;
+ } else {
+ return maximumSpeedInKmph;
+ }
+ }
+
+ /**
+ * How many seconds does it take to reach maximum speed based on initial speed and acceleration.
+ *
+ * @param initialSpeedInKmph How fast the vehicle is travelling at the start of the calculation
+ * @param maxSpeedInKmph The target speed to be reached
+ * @return How long it takes to reach the speed in seconds
+ */
+ private double durationToMaxSpeed(double initialSpeedInKmph, double maxSpeedInKmph) {
+ return (maxSpeedInKmph - initialSpeedInKmph) / accelerationKmpHpS();
+ }
+
+ /**
+ * How long in seconds does it take to reach the intended distance based on the initial travelling speed and the
+ * maximum speed that can be travelled.
+ *
+ * @param initialSpeedInKmph The speed of the vehicle when starting the calculation
+ * @param maxSpeedInKmph The maximum speed the vehicle can travel at
+ * @param distanceInM The target distance to be travelled
+ * @return How long it takes in seconds to reach the target distance
+ */
+ private double durationToTravelDistance(double initialSpeedInKmph, double maxSpeedInKmph, double distanceInM) {
+ double secondsTravelled = 0;
+ double distanceTravelled = 0;
+
+ double currentSpeed = initialSpeedInKmph;
+
+ while(currentSpeed < maxSpeedInKmph && distanceTravelled < distanceInM) {
+ currentSpeed += accelerationKmpHpS();
+ secondsTravelled += 1;
+ distanceTravelled += convertKmphToMps(currentSpeed);
+ }
+
+ double distanceRemaining = distanceInM - distanceTravelled;
+
+ if(distanceRemaining > 0) {
+ secondsTravelled += (distanceRemaining / convertKmphToMps(maxSpeedInKmph));
+ }
+
+ return secondsTravelled;
+ }
+
+ /**
+ * How far can the vehicle travel in the specified time frame
+ *
+ * @param initialSpeedInKmph The starting speed of the vehicle
+ * @param maxSpeedInKmph The maximum travel speed
+ * @param duration How long is the vehicle travelling for
+ * @return The distance in metres that the vehicle travels in the specified time
+ */
+ private double distanceTravelledInDuration(double initialSpeedInKmph, double maxSpeedInKmph, double duration) {
+ double secondsTravelled = 0;
+ double distanceTravelled = 0;
+ double currentSpeed = initialSpeedInKmph;
+
+ while(currentSpeed < maxSpeedInKmph && secondsTravelled < duration) {
+ currentSpeed += accelerationKmpHpS();
+ secondsTravelled += 1;
+ distanceTravelled += convertKmphToMps(currentSpeed);
+ }
+
+ double secondsRemaining = duration - secondsTravelled;
+
+ if(secondsRemaining > 0 ) {
+ distanceTravelled += (secondsRemaining * convertKmphToMps(maxSpeedInKmph));
+ }
+
+ return distanceTravelled;
+ }
+
+ /**
+ * Convert kilometres per hour to metres per second
+ *
+ * @param speedInKmph The speed to be converted in km per hour
+ * @return The speed in metres per second
+ */
+ private double convertKmphToMps(double speedInKmph) {
+ return (speedInKmph * 1000) / 3600;
+ }
+
+ /**
+ * Convert metres per second to kilometres per hour
+ *
+ * @param speedInMps The speed in metres per second
+ * @return The speed in kilometres per hour
+ */
+ private double convertMpsToKmph(double speedInMps) {
+ return (3600 * speedInMps) / 1000;
+ }
+}
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/WheelchairFlagEncoder.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/WheelchairFlagEncoder.java
index e4a4deb182..4c6aa018ba 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/WheelchairFlagEncoder.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/WheelchairFlagEncoder.java
@@ -16,7 +16,6 @@
import com.graphhopper.reader.ReaderNode;
import com.graphhopper.reader.ReaderRelation;
import com.graphhopper.reader.ReaderWay;
-import com.graphhopper.routing.util.AbstractFlagEncoder;
import com.graphhopper.routing.util.EncodedDoubleValue;
import com.graphhopper.routing.util.EncodedValue;
import com.graphhopper.routing.util.PriorityCode;
@@ -28,54 +27,43 @@
import static com.graphhopper.routing.util.PriorityCode.*;
-public class WheelchairFlagEncoder extends AbstractFlagEncoder
-{
- static final int SLOW_SPEED = 2;
+public class WheelchairFlagEncoder extends FootFlagEncoder {
public static final int MEAN_SPEED = 4;
- static final int FERRY_SPEED = 10;
static final int MAX_SPEED = 15;
- private EncodedValue priorityWayEncoder;
- private EncodedValue relationCodeEncoder;
-
- private final Set usableSidewalkValues = new HashSet();
- private final Set noSidewalkValues = new HashSet();
- // convert network tag of hiking routes into a way route code
- private final Map hikingNetworkToCode = new HashMap();
-
- protected HashSet acceptedPublicTransport = new HashSet(5);
+ protected Set acceptedPublicTransport = new HashSet<>(5);
/**
* Fully suitable for wheelchair users
*/
- private final Set fullyWheelchairAccessibleHighways = new HashSet();
+ private final Set fullyWheelchairAccessibleHighways = new HashSet<>();
/**
* Suitable for wheelchair users. However highways falling into this category that explicitly indicate a sidewalk is available will be prefered
*/
- private final Set assumedWheelchairAccessibleHighways = new HashSet();
+ private final Set assumedWheelchairAccessibleHighways = new HashSet<>();
/**
* Highways that fall into this category will only be considered if further information about surface/smoothness is available
*/
- private final Set limitedWheelchairAccessibleHighways = new HashSet();
+ private final Set limitedWheelchairAccessibleHighways = new HashSet<>();
/**
* Highways that fall into this category will only be considered if further information about surface/smoothness is available
*/
- private final Set restrictedWheelchairHighways = new HashSet();
+ private final Set restrictedWheelchairHighways = new HashSet<>();
/**
* Highways that fall into this category cannot be accessed by Wheelchair users (e.g. steps)
*/
- private final Set nonWheelchairAccessibleHighways = new HashSet();
+ private final Set nonWheelchairAccessibleHighways = new HashSet<>();
/**
* Barriers (nodes) that are not accessible. Routes that would these nodes are not possible.
*/
- private HashSet inaccessibleBarriers = new HashSet(5);
+ private Set inaccessibleBarriers = new HashSet<>(5);
- private final Set accessibilityRelatedAttributes = new HashSet();
+ private final Set accessibilityRelatedAttributes = new HashSet<>();
public WheelchairFlagEncoder(PMap configuration)
{
@@ -93,34 +81,12 @@ public WheelchairFlagEncoder()
public WheelchairFlagEncoder( int speedBits, double speedFactor )
{
- super(speedBits, speedFactor, 0);
+ super(speedBits, speedFactor);
// test for the following restriction keys
- restrictions.addAll(Arrays.asList("foot", "access", "wheelchair"));
-
- // for nodes: these values make the node impassable for any value of restrictions
- // for ways: these values make the way impassable for any value of restrictions
- restrictedValues.add("private");
- restrictedValues.add("no");
- restrictedValues.add("restricted");
-
- intendedValues.add("yes");
- intendedValues.add("designated");
- intendedValues.add("official");
- intendedValues.add("permissive");
- // TODO: include limited here or not? maybe make this is an parameter, selectable via client UI?
+ restrictions.add("wheelchair");
+
intendedValues.add("limited");
- usableSidewalkValues.add("yes");
- usableSidewalkValues.add("both");
- usableSidewalkValues.add("left");
- usableSidewalkValues.add("right");
-
- noSidewalkValues.add("no");
- noSidewalkValues.add("none");
- noSidewalkValues.add("separate");
- noSidewalkValues.add("seperate");
- noSidewalkValues.add("detached");
-
// http://wiki.openstreetmap.org/wiki/Key:barrier
// http://taginfo.openstreetmap.org/keys/?key=barrier#values
@@ -204,36 +170,19 @@ public WheelchairFlagEncoder( int speedBits, double speedFactor )
accessibilityRelatedAttributes.add("incline");
accessibilityRelatedAttributes.add("sloped_curb");
accessibilityRelatedAttributes.add("sloped_kerb");
-
- // prefer international, national, regional or local hiking routes
- hikingNetworkToCode.put("iwn", BEST.getValue());
- hikingNetworkToCode.put("nwn", BEST.getValue());
- hikingNetworkToCode.put("rwn", VERY_NICE.getValue());
- hikingNetworkToCode.put("lwn", VERY_NICE.getValue());
init();
}
+
+ public double getMeanSpeed() {
+ return MEAN_SPEED;
+ }
public double getDefaultMaxSpeed()
{
return 4;
}
- @Override
- public int defineWayBits( int index, int shift )
- {
- // first 3 bits are reserved for route handling in superclass
- shift = super.defineWayBits(index, shift);
- // larger value required - ferries are faster than pedestrians (4 bits)
- speedEncoder = new EncodedDoubleValue("Speed", shift, speedBits, speedFactor, MEAN_SPEED, MAX_SPEED);
- shift += speedEncoder.getBits();
-
- priorityWayEncoder = new EncodedValue("PreferWay", shift, 3, 1, 0, 7);
- shift += priorityWayEncoder.getBits();
-
- return shift;
- }
-
@Override
public int defineNodeBits(int index, int shift) {
shift = super.defineNodeBits(index, shift);
@@ -286,49 +235,6 @@ public long setNonSidewalkSpeed(long flags)
// return adaptSpeed(flags, 1d);
}
- @Override
- public int defineRelationBits( int index, int shift )
- {
- relationCodeEncoder = new EncodedValue("RelationCode", shift, 3, 1, 0, 7);
- return shift + relationCodeEncoder.getBits();
- }
-
- /**
- * Wheelchair flag encoder does not provide any turn cost / restrictions
- */
- @Override
- public int defineTurnBits( int index, int shift )
- {
- return shift;
- }
-
- /**
- * Wheelchair flag encoder does not provide any turn cost / restrictions
- *
- * @return false
- */
- @Override
- public boolean isTurnRestricted( long flag )
- {
- return false;
- }
-
- /**
- * Foot flag encoder does not provide any turn cost / restrictions
- *
- * @return 0
- */
- @Override
- public double getTurnCost( long flag )
- {
- return 0;
- }
-
- @Override
- public long getTurnFlags( boolean restricted, double costs )
- {
- return 0;
- }
/**
* Some ways are okay but not separate for pedestrians.
@@ -679,26 +585,6 @@ public void applyWayTags(ReaderWay way, EdgeIteratorState edge )
}
*/
}
-
-
-
-
-
- @Override
- public double getDouble(long flags, int key)
- {
- switch (key)
- {
- case PriorityWeighting.KEY:
- double prio = priorityWayEncoder.getValue(flags);
- if (prio == 0)
- return (double) UNCHANGED.getValue() / (double) BEST.getValue();
-
- return prio / (double) BEST.getValue();
- default:
- return super.getDouble(flags, key);
- }
- }
@Override
// currently unused
@@ -830,8 +716,6 @@ else if (way.hasTag("foot", intendedValues) || way.hasTag("bicycle", "designated
int sum = positiveFeatures - negativeFeatures;
- // System.out.println("WheelchairFlagEncoder.collect(), sum="+sum+", wayId="+way.getId());
-
if (sum <= -6) weightToPrioMap.put(2d, AVOID_AT_ALL_COSTS.getValue());
else if (sum >= -5 && sum <= -3) weightToPrioMap.put(2d, REACH_DEST.getValue());
else if (sum >= -2 && sum <= -1) weightToPrioMap.put(2d, AVOID_IF_POSSIBLE.getValue());
@@ -840,16 +724,6 @@ else if (way.hasTag("foot", intendedValues) || way.hasTag("bicycle", "designated
else if (sum >= 3 && sum <= 5) weightToPrioMap.put(2d, VERY_NICE.getValue());
else if (sum >= 6) weightToPrioMap.put(2d, BEST.getValue());
}
-
-
- @Override
- public boolean supports( Class> feature )
- {
- if (super.supports(feature))
- return true;
-
- return PriorityWeighting.class.isAssignableFrom(feature);
- }
@Override
public String toString()
@@ -861,6 +735,4 @@ public String toString()
public int getVersion() {
return 2;
}
-
-
}
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/CommonBikeFlagEncoder.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/CommonBikeFlagEncoder.java
index 881ee1efb2..7ce565480e 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/CommonBikeFlagEncoder.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/CommonBikeFlagEncoder.java
@@ -22,6 +22,7 @@
import com.graphhopper.routing.util.*;
import com.graphhopper.routing.weighting.PriorityWeighting;
import com.graphhopper.util.*;
+import heigit.ors.routing.graphhopper.extensions.flagencoders.ORSAbstractFlagEncoder;
import org.apache.log4j.Logger;
import java.util.*;
@@ -37,7 +38,7 @@
* @author Nop
* @author ratrun
*/
-abstract public class CommonBikeFlagEncoder extends AbstractFlagEncoder {
+abstract public class CommonBikeFlagEncoder extends ORSAbstractFlagEncoder {
/**
* Reports whether this edge is unpaved.
*/
@@ -246,7 +247,7 @@ public int defineWayBits(int index, int shift) {
shift += priorityWayEncoder.getBits();
// MARQ24 MOD START
- if (isConsiderElevation()) {
+ if (considerElevation) {
reverseSpeedEncoder = new EncodedDoubleValue("Reverse Speed", shift, speedBits, speedFactor, getHighwaySpeed("cycleway").speed, maxPossibleSpeed);
shift += reverseSpeedEncoder.getBits();
}
@@ -1044,7 +1045,7 @@ public String toString(){
@Override
public void applyWayTags(ReaderWay way, EdgeIteratorState edge) {
// MARQ24 MOD START
- if (isConsiderElevation()) {
+ if (considerElevation) {
// MARQ24 MOD END
PointList pl = edge.fetchWayGeometry(3);
if (!pl.is3D())
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/ElectroBikeFlagEncoder.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/ElectroBikeFlagEncoder.java
index 2bdcde716d..280ede980e 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/ElectroBikeFlagEncoder.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/ElectroBikeFlagEncoder.java
@@ -18,7 +18,8 @@
public class ElectroBikeFlagEncoder extends CommonBikeFlagEncoder
{
-
+ private static final int MEAN_SPEED = 20;
+
public ElectroBikeFlagEncoder()
{
this(4, 2, 0, false);
@@ -129,6 +130,10 @@ public ElectroBikeFlagEncoder( int speedBits, double speedFactor, int maxTurnCos
this.init();
}
+ public double getMeanSpeed() {
+ return MEAN_SPEED;
+ }
+
@Override
public int getVersion()
{
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/MountainBikeFlagEncoder.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/MountainBikeFlagEncoder.java
index fd519f1dc8..530efa25a2 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/MountainBikeFlagEncoder.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/MountainBikeFlagEncoder.java
@@ -34,6 +34,8 @@
* @author Peter Karich
*/
public class MountainBikeFlagEncoder extends CommonBikeFlagEncoder {
+ private static final int MEAN_SPEED = 14;
+
public MountainBikeFlagEncoder() {
// MARQ24 MOD START
//this(4, 2, 0);
@@ -151,6 +153,10 @@ public MountainBikeFlagEncoder(int speedBits, double speedFactor, int maxTurnCos
init();
}
+ public double getMeanSpeed() {
+ return MEAN_SPEED;
+ }
+
@Override
public int getVersion() {
return 2;
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/RegularBikeFlagEncoder.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/RegularBikeFlagEncoder.java
index d2e98d7ace..a2e4eb5fc2 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/RegularBikeFlagEncoder.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/RegularBikeFlagEncoder.java
@@ -29,6 +29,8 @@
* @author Peter Karich
*/
public class RegularBikeFlagEncoder extends CommonBikeFlagEncoder {
+ private static final int MEAN_SPEED = 15;
+
public RegularBikeFlagEncoder() {
// MARQ24 MOD START
//this(4, 2, 0);
@@ -86,6 +88,10 @@ public RegularBikeFlagEncoder(int speedBits, double speedFactor, int maxTurnCost
init();
}
+ public double getMeanSpeed() {
+ return MEAN_SPEED;
+ }
+
@Override
public int getVersion() {
return 2;
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/RoadBikeFlagEncoder.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/RoadBikeFlagEncoder.java
index 0b19150bdc..6c214800d7 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/RoadBikeFlagEncoder.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/bike/RoadBikeFlagEncoder.java
@@ -34,6 +34,8 @@
* @author Peter Karich
*/
public class RoadBikeFlagEncoder extends CommonBikeFlagEncoder {
+ private static final int MEAN_SPEED = 25;
+
public RoadBikeFlagEncoder() {
// MARQ24 MOD START
//this(4, 2, 0);
@@ -196,6 +198,10 @@ public RoadBikeFlagEncoder(int speedBits, double speedFactor, int maxTurnCosts,
this.init();
}
+ public double getMeanSpeed() {
+ return MEAN_SPEED;
+ }
+
@Override
public int getVersion() {
return 2;
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/currentlynotinuse/ExGhORSCarFlagEncoder.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/currentlynotinuse/ExGhORSCarFlagEncoder.java
index a1afbdba01..15294c2910 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/currentlynotinuse/ExGhORSCarFlagEncoder.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/flagencoders/currentlynotinuse/ExGhORSCarFlagEncoder.java
@@ -23,6 +23,7 @@
import com.graphhopper.routing.util.EncodedDoubleValue;
import com.graphhopper.util.Helper;
import com.graphhopper.util.PMap;
+import heigit.ors.routing.graphhopper.extensions.flagencoders.ORSAbstractFlagEncoder;
import java.util.*;
@@ -33,7 +34,8 @@
* @author Peter Karich
* @author Nop
*/
-public class ExGhORSCarFlagEncoder extends AbstractFlagEncoder {
+public class ExGhORSCarFlagEncoder extends ORSAbstractFlagEncoder {
+ private final static double MEAN_SPEED = 100;
protected final Map trackTypeSpeedMap = new HashMap();
protected final Set badSurfaceSpeedMap = new HashSet();
@@ -57,6 +59,8 @@ public ExGhORSCarFlagEncoder() {
this(5, 5, 0);
}
+ public double getMeanSpeed() { return MEAN_SPEED; }
+
public ExGhORSCarFlagEncoder(PMap properties) {
this((int) properties.getLong("speed_bits", 5),
properties.getDouble("speed_factor", 5),
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/reader/borders/CountryBordersReader.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/reader/borders/CountryBordersReader.java
index b550a63ce4..6baefcb97e 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/reader/borders/CountryBordersReader.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/reader/borders/CountryBordersReader.java
@@ -15,7 +15,6 @@
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.geom.Point;
import heigit.ors.geojson.GeometryJSON;
import heigit.ors.util.CSVUtility;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/AccessRestrictionsGraphStorage.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/AccessRestrictionsGraphStorage.java
deleted file mode 100644
index 58e99db32b..0000000000
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/AccessRestrictionsGraphStorage.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/* This file is part of Openrouteservice.
- *
- * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
- * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
-
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU Lesser General Public License for more details.
-
- * You should have received a copy of the GNU Lesser General Public License along with this library;
- * if not, see .
- */
-package heigit.ors.routing.graphhopper.extensions.storages;
-
-import com.graphhopper.storage.DataAccess;
-import com.graphhopper.storage.Directory;
-import com.graphhopper.storage.Graph;
-import com.graphhopper.storage.GraphExtension;
-
-import heigit.ors.routing.RoutingProfileType;
-
-public class AccessRestrictionsGraphStorage implements GraphExtension {
- /* pointer for no entry */
- protected final int NO_ENTRY = -1;
- protected final int EF_RESTRICTIONS;
-
- protected DataAccess edges;
- protected int edgeEntryIndex = 0;
- protected int edgeEntryBytes;
- protected int edgesCount;
- private byte[] byteValues;
- private boolean _hasMotorVehicles = false;
- private boolean _hasNonMotorVehicles = false;
-
- public AccessRestrictionsGraphStorage(int[] profileTypes)
- {
- for (int i = 0; i < profileTypes.length; i++)
- {
- int rp = profileTypes[i];
- if (RoutingProfileType.isCycling(rp) || RoutingProfileType.isWalking(rp) )
- _hasNonMotorVehicles = true;
- else if (RoutingProfileType.isDriving(rp))
- _hasMotorVehicles = true;
- }
-
- // we allocate 1 or 2 bytes for 4 profiles (motorcar, motorcycle, bicycle, foot), each profile might occupy maximum 4 bits
- EF_RESTRICTIONS = nextBlockEntryIndex (_hasMotorVehicles && _hasNonMotorVehicles ? 2 : 1);
-
- edgeEntryBytes = edgeEntryIndex;
- edgesCount = 0;
- byteValues = new byte[2];
- }
-
- public void init(Graph graph, Directory dir) {
- if (edgesCount > 0)
- throw new AssertionError("The ext_access_restrictions storage must be initialized only once.");
-
- this.edges = dir.find("ext_access_restrictions");
- }
-
- protected final int nextBlockEntryIndex(int size) {
- int res = edgeEntryIndex;
- edgeEntryIndex += size;
- return res;
- }
-
- public void setSegmentSize(int bytes) {
- edges.setSegmentSize(bytes);
- }
-
- public GraphExtension create(long initBytes) {
- edges.create((long) initBytes * edgeEntryBytes);
- return this;
- }
-
- public void flush() {
- edges.setHeader(0, edgeEntryBytes);
- edges.setHeader(1 * 4, edgesCount);
- edges.flush();
- }
-
- public void close() {
- edges.close();
- }
-
- public long getCapacity() {
- return edges.getCapacity();
- }
-
- public int entries() {
- return edgesCount;
- }
-
- public boolean loadExisting() {
- if (!edges.loadExisting())
- throw new IllegalStateException("Unable to load storage 'ext_access_restrictions'. corrupt file or directory? ");
-
- edgeEntryBytes = edges.getHeader(0);
- edgesCount = edges.getHeader(4);
- return true;
- }
-
- void ensureEdgesIndex(int edgeIndex) {
- edges.ensureCapacity(((long) edgeIndex + 1) * edgeEntryBytes);
- }
-
- public void setEdgeValue(int edgeId, int[] restrictions) {
- edgesCount++;
- ensureEdgesIndex(edgeId);
-
- long edgePointer = (long) edgeId * edgeEntryBytes;
-
- if (restrictions != null)
- {
- if (_hasMotorVehicles && _hasNonMotorVehicles)
- {
- byteValues[0] = (byte)(restrictions[0] << 4 | (0x0F & restrictions[1]));
- byteValues[1] = (byte)(restrictions[2] << 4 | (0x0F & restrictions[3]));
- edges.setBytes(edgePointer + EF_RESTRICTIONS, byteValues, 2);
- }
- else
- {
- if (_hasMotorVehicles)
- byteValues[0] = (byte)(restrictions[0] << 4 | (0x0F & restrictions[1]));
- else
- byteValues[0] = (byte)(restrictions[2] << 4 | (0x0F & restrictions[3]));
-
- edges.setBytes(edgePointer + EF_RESTRICTIONS, byteValues, 1);
- }
- }
- }
-
- //vehicleType can take the following values
- // motorcar = 0
- // motorcycle = 1
- // bicycle = 2
- // foot = 3
- public int getEdgeValue(int edgeId, int vehicleType, byte[] buffer) {
- long edgeBase = (long) edgeId * edgeEntryBytes;
-
- if (vehicleType == 0 || vehicleType == 1)
- {
- edges.getBytes(edgeBase + EF_RESTRICTIONS, buffer, 1);
-
- byte value = buffer[0];
- if (value != 0)
- {
- if (vehicleType == 1)
- return value & 0xF;
- else
- return (value >> 4) & 0xF;
- }
- }
- else
- {
- if (_hasMotorVehicles)
- edges.getBytes(edgeBase + EF_RESTRICTIONS + 1, buffer, 1);
- else
- edges.getBytes(edgeBase + EF_RESTRICTIONS, buffer, 1);
-
- byte value = buffer[0];
- if (value != 0)
- {
- if (vehicleType == 2)
- return value & 0xF;
- else
- return (value >> 4) & 0xF;
- }
- }
-
- return 0;
- }
-
- public boolean isRequireNodeField() {
- return true;
- }
-
- public boolean isRequireEdgeField() {
- // we require the additional field in the graph to point to the first
- // entry in the node table
- return true;
- }
-
- public int getDefaultNodeFieldValue() {
- return -1;
- // throw new UnsupportedOperationException("Not supported by this storage");
- }
-
- public int getDefaultEdgeFieldValue() {
- return -1;
- }
-
- public GraphExtension copyTo(GraphExtension clonedStorage) {
- if (!(clonedStorage instanceof AccessRestrictionsGraphStorage)) {
- throw new IllegalStateException("the extended storage to clone must be the same");
- }
-
- AccessRestrictionsGraphStorage clonedTC = (AccessRestrictionsGraphStorage) clonedStorage;
-
- edges.copyTo(clonedTC.edges);
- clonedTC.edgesCount = edgesCount;
-
- return clonedStorage;
- }
-
- @Override
- public boolean isClosed() {
- // TODO Auto-generated method stub
- return false;
- }
-}
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/BordersGraphStorage.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/BordersGraphStorage.java
index da65ef4fec..9093232d0f 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/BordersGraphStorage.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/BordersGraphStorage.java
@@ -1,15 +1,15 @@
/* This file is part of Openrouteservice.
*
- * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
- * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
+ * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License along with this library;
- * if not, see .
+ * You should have received a copy of the GNU Lesser General Public License along with this library;
+ * if not, see .
*/
package heigit.ors.routing.graphhopper.extensions.storages;
@@ -19,11 +19,15 @@
import com.graphhopper.storage.GraphExtension;
import com.graphhopper.storage.RAMDirectory;
+import org.apache.log4j.Logger;
+
/**
* Graph storage class for the Border Restriction routing
*/
public class BordersGraphStorage implements GraphExtension {
- public enum Property { TYPE, START, END };
+ private static final Logger LOGGER = Logger.getLogger(BordersGraphStorage.class.getName());
+
+ public enum Property { TYPE, START, END}
/* pointer for no entry */
protected final int NO_ENTRY = -1;
private final int EF_BORDER = 0; // byte location of border type
@@ -40,7 +44,6 @@ public enum Property { TYPE, START, END };
private int edgesCount; // number of edges with custom values
public BordersGraphStorage() {
- //EF_BORDER = 0;
int edgeEntryIndex = 0;
edgeEntryBytes = edgeEntryIndex + 6; // item uses 3 short values which are 2 bytes length each
@@ -52,11 +55,10 @@ public BordersGraphStorage() {
*
* This method takes the internal ID of the edge and adds the information obtained from the Borders CSV file to it
* so that the values can be taken into account when generating a route.
- *
- * @param edgeId Internal ID of the graph edge
- * @param borderType Level of border crossing (0 - No border, 1 - controlled border, 2 - open border=
- * @param start ID of the country that the edge starts in
- * @param end ID of the country that the edge ends in
+ * @param edgeId Internal ID of the graph edge
+ * @param borderType Level of border crossing (0 - No border, 1 - controlled border, 2 - open border=
+ * @param start ID of the country that the edge starts in
+ * @param end ID of the country that the edge ends in
*/
public void setEdgeValue(int edgeId, short borderType, short start, short end) {
edgesCount++;
@@ -74,24 +76,22 @@ public void setEdgeValue(int edgeId, short borderType, short start, short end) {
/**
* Get the specified custom value of the edge that was assigned to it in the setValueEdge method
- *
+ *
* The method takes an identifier to the edge and then gets the requested value for the edge from the storage
*
- * @param edgeId Internal ID of the edge to get values for
- * @param prop The property of the edge to get (TYPE - border type (0,1,2), START - the ID of the country
- * the edge starts in, END - the ID of the country the edge ends in.
- * @return The value of the requested property
+ * @param edgeId Internal ID of the edge to get values for
+ * @param prop The property of the edge to get (TYPE - border type (0,1,2), START - the ID of the country
+ * the edge starts in, END - the ID of the country the edge ends in.
+ * @return The value of the requested property
*/
public short getEdgeValue(int edgeId, Property prop) {
long edgePointer = (long) edgeId * edgeEntryBytes;
- short border = 0, start = 0, end = 0;
- border = orsEdges.getShort(edgePointer + EF_BORDER);
- start = orsEdges.getShort(edgePointer + EF_START);
- end = orsEdges.getShort(edgePointer + EF_END);
+ short border = orsEdges.getShort(edgePointer + EF_BORDER);
+ short start = orsEdges.getShort(edgePointer + EF_START);
+ short end = orsEdges.getShort(edgePointer + EF_END);
switch (prop) {
case TYPE:
-
return border;
case START:
return start;
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/EmergencyVehicleAttributesGraphStorage.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/EmergencyVehicleAttributesGraphStorage.java
deleted file mode 100644
index 7565b50193..0000000000
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/EmergencyVehicleAttributesGraphStorage.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/* This file is part of Openrouteservice.
- *
- * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
- * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
-
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU Lesser General Public License for more details.
-
- * You should have received a copy of the GNU Lesser General Public License along with this library;
- * if not, see .
- */
-package heigit.ors.routing.graphhopper.extensions.storages;
-
-import com.graphhopper.storage.Directory;
-import com.graphhopper.storage.Graph;
-
-public class EmergencyVehicleAttributesGraphStorage extends HeavyVehicleAttributesGraphStorage {
- public EmergencyVehicleAttributesGraphStorage(boolean includeRestrictions) {
- super(includeRestrictions);
-
- }
-
- /* pointer for no entry */
- public void init(Graph graph, Directory dir) {
- if (edgesCount > 0)
- throw new AssertionError("The ext_emergency storage must be initialized only once.");
-
- this.orsEdges = dir.find("ext_emergency");
- }
-
- public boolean loadExisting() {
- if (!orsEdges.loadExisting())
- throw new IllegalStateException("Unable to load storage 'ext_emergency'. corrupt file or directory? ");
-
- edgeEntryBytes = orsEdges.getHeader(0);
- edgesCount = orsEdges.getHeader(4);
- return true;
- }
-}
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/HeavyVehicleAttributesGraphStorage.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/HeavyVehicleAttributesGraphStorage.java
index a3b19ac522..c192c3e708 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/HeavyVehicleAttributesGraphStorage.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/HeavyVehicleAttributesGraphStorage.java
@@ -113,7 +113,7 @@ public void setEdgeValue(int edgeId, int vehicleType, int heavyVehicleDestinatio
throw new IllegalStateException("EF_RESTRICTION is not supported.");
for (int i = 0; i < VehicleDimensionRestrictions.Count; i++) {
- short shortValue = restrictionValues == null ? 0 : (short) (restrictionValues[i] * factor);
+ short shortValue = (short) (restrictionValues[i] * factor);
orsEdges.setShort(edgePointer + EF_RESTRICTIONS + i * EF_RESTRICTION_BYTES, shortValue);
}
}
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/RoadAccessRestrictionsGraphStorage.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/RoadAccessRestrictionsGraphStorage.java
index fefd86d185..c78c45c552 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/RoadAccessRestrictionsGraphStorage.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/RoadAccessRestrictionsGraphStorage.java
@@ -138,11 +138,11 @@ public int getDefaultEdgeFieldValue() {
}
public GraphExtension copyTo(GraphExtension clonedStorage) {
- if (!(clonedStorage instanceof AccessRestrictionsGraphStorage)) {
+ if (!(clonedStorage instanceof RoadAccessRestrictionsGraphStorage)) {
throw new IllegalStateException("the extended storage to clone must be the same");
}
- AccessRestrictionsGraphStorage clonedTC = (AccessRestrictionsGraphStorage) clonedStorage;
+ RoadAccessRestrictionsGraphStorage clonedTC = (RoadAccessRestrictionsGraphStorage) clonedStorage;
edges.copyTo(clonedTC.edges);
clonedTC.edgesCount = edgesCount;
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/AccessRestrictionsGraphStorageBuilder.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/AccessRestrictionsGraphStorageBuilder.java
deleted file mode 100644
index 76a76bdbc3..0000000000
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/AccessRestrictionsGraphStorageBuilder.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/* This file is part of Openrouteservice.
- *
- * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
- * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
-
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU Lesser General Public License for more details.
-
- * You should have received a copy of the GNU Lesser General Public License along with this library;
- * if not, see .
- */
-package heigit.ors.routing.graphhopper.extensions.storages.builders;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import com.graphhopper.GraphHopper;
-import com.graphhopper.reader.ReaderWay;
-import com.graphhopper.routing.util.EncodingManager;
-import com.graphhopper.routing.util.FlagEncoder;
-import com.graphhopper.storage.GraphExtension;
-import com.graphhopper.util.EdgeIteratorState;
-
-import heigit.ors.routing.RoutingProfileType;
-import heigit.ors.routing.graphhopper.extensions.AccessRestrictionType;
-import heigit.ors.routing.graphhopper.extensions.storages.AccessRestrictionsGraphStorage;
-
-public class AccessRestrictionsGraphStorageBuilder extends AbstractGraphStorageBuilder
-{
- private AccessRestrictionsGraphStorage _storage;
- private boolean _hasRestrictions = false;
- private int[] _restrictions = new int[4];
- private List _accessRestrictedTags = new ArrayList(5);
- private List _motorCarTags = new ArrayList(5);
- private List _motorCycleTags = new ArrayList(5);
- private Set _restrictedValues = new HashSet(5);
- private Set _permissiveValues = new HashSet(5);
-
- public AccessRestrictionsGraphStorageBuilder()
- {
- _accessRestrictedTags.addAll(Arrays.asList("motorcar", "motor_vehicle", "vehicle", "access"));
- _motorCarTags.addAll(Arrays.asList("motorcar", "motor_vehicle"));
- _motorCycleTags.addAll(Arrays.asList("motorcycle", "motor_vehicle"));
-
- _restrictedValues.add("private");
- _restrictedValues.add("no");
- _restrictedValues.add("restricted");
- _restrictedValues.add("military");
- _restrictedValues.add("destination");
- _restrictedValues.add("customers");
- _restrictedValues.add("emergency");
-
- _permissiveValues.add("yes");
- _permissiveValues.add("designated");
- _permissiveValues.add("official");
- _permissiveValues.add("permissive");
- }
-
- public GraphExtension init(GraphHopper graphhopper) throws Exception {
- if (_storage != null)
- throw new Exception("GraphStorageBuilder has been already initialized.");
-
- // extract profiles from GraphHopper instance
- EncodingManager encMgr = graphhopper.getEncodingManager();
- List encoders = encMgr.fetchEdgeEncoders();
- int[] profileTypes = new int[encoders.size()];
- int i = 0;
- for (FlagEncoder enc : encoders)
- {
- profileTypes[i] = RoutingProfileType.getFromEncoderName(enc.toString());
- i++;
- }
-
- _storage = new AccessRestrictionsGraphStorage(profileTypes);
-
- return _storage;
- }
-
- public void processWay(ReaderWay way) {
-
- if (_hasRestrictions)
- {
- _hasRestrictions = false;
-
- _restrictions[0] = 0;
- _restrictions[1] = 0;
- _restrictions[2] = 0;
- _restrictions[3] = 0;
- }
-
- if (way.hasTag(_accessRestrictedTags, _restrictedValues))
- {
- _hasRestrictions = true;
-
- _restrictions[0] = isAccessAllowed(way, _motorCarTags) ? 0 : getRestrictionType(way, _motorCarTags);
- _restrictions[1] = isAccessAllowed(way, _motorCycleTags) ? 0 : getRestrictionType(way, _motorCycleTags);
- _restrictions[2] = isAccessAllowed(way, "bicycle") ? 0 : getRestrictionType(way, "bicycle");
- _restrictions[3] = isAccessAllowed(way, "foot") ? 0 : getRestrictionType(way, "foot");
- }
-
- if (!_hasRestrictions)
- {
- // way 316156033
- if (way.hasTag("foot", _permissiveValues) || way.hasTag("bicycle", _permissiveValues))
- {
- _hasRestrictions = true;
-
- _restrictions[0] = !isAccessAllowed(way, _motorCarTags) ? 0 : getRestrictionType(way, _motorCarTags);
- if (_restrictions[0] == 0)
- _restrictions[0] = AccessRestrictionType.No;
- _restrictions[1] = !isAccessAllowed(way, _motorCycleTags) ? 0 : getRestrictionType(way, _motorCycleTags);
- if (_restrictions[1] == 0)
- _restrictions[1] = AccessRestrictionType.No;
- }
- }
- }
-
- private int getRestrictionType(ReaderWay way, List tags)
- {
- int res = 0;
-
- String tagValue = way.getTag("access");
- if (tagValue != null && tagValue.equals("customers"))
- res |= AccessRestrictionType.Customers;
-
- if (tags != null)
- {
- for (String key : tags)
- {
- tagValue = way.getTag(key);
- if (tagValue != null)
- {
- if (tagValue.equals("no"))
- res |= AccessRestrictionType.No;
- if (tagValue.equals("destination"))
- res |= AccessRestrictionType.Destination;
- }
- }
- }
-
- return res;
- }
-
- private int getRestrictionType(ReaderWay way, String tag)
- {
- int res = 0;
-
- String tagValue = way.getTag("access");
- if (tagValue != null && tagValue.equals("customers"))
- res |= AccessRestrictionType.Customers;
-
- tagValue = way.getTag(tag);
- if (tagValue != null)
- {
- if (tagValue.equals("no"))
- res |= AccessRestrictionType.No;
- if (tagValue.equals("destination"))
- res |= AccessRestrictionType.Destination;
- }
-
- return res;
- }
-
- private boolean isAccessAllowed(ReaderWay way, List tagNames)
- {
- return way.hasTag(tagNames, _permissiveValues);
- }
-
- private boolean isAccessAllowed(ReaderWay way, String tagName)
- {
- return way.hasTag(tagName, _permissiveValues);
- }
-
- public void processEdge(ReaderWay way, EdgeIteratorState edge)
- {
- if (_hasRestrictions)
- _storage.setEdgeValue(edge.getEdge(), _restrictions);
- }
-
- @Override
- public String getName() {
- return "AccessRestrictions";
- }
-}
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/BordersGraphStorageBuilder.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/BordersGraphStorageBuilder.java
index 8b0df345ff..bb0897d7a9 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/BordersGraphStorageBuilder.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/BordersGraphStorageBuilder.java
@@ -1,15 +1,15 @@
/* This file is part of Openrouteservice.
*
- * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
- * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
+ * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License along with this library;
- * if not, see .
+ * You should have received a copy of the GNU Lesser General Public License along with this library;
+ * if not, see .
*/
package heigit.ors.routing.graphhopper.extensions.storages.builders;
@@ -20,7 +20,6 @@
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString;
-import com.vividsolutions.jts.geom.Point;
import heigit.ors.exceptions.MissingConfigParameterException;
import heigit.ors.routing.graphhopper.extensions.reader.borders.CountryBordersPolygon;
import heigit.ors.routing.graphhopper.extensions.reader.borders.CountryBordersReader;
@@ -44,6 +43,8 @@ public class BordersGraphStorageBuilder extends AbstractGraphStorageBuilder {
private GeometryFactory gf;
+ public static String builderName = "Borders";
+
public BordersGraphStorageBuilder() {
gf = new GeometryFactory();
}
@@ -119,13 +120,15 @@ public void processWay(ReaderWay way) {
public void processWay(ReaderWay way, Coordinate[] coords, HashMap> nodeTags) {
// Process the way using the geometry provided
// if we don't have the reader object, then we can't do anything
- if(cbReader != null) {
+ if (cbReader != null) {
String[] countries = findBorderCrossing(coords);
-
// If we find that the length of countries is more than one, then it does cross a border
if (countries.length > 1 && !countries[0].equals(countries[1])) {
way.setTag("country1", countries[0]);
way.setTag("country2", countries[1]);
+ } else if (countries.length == 1){
+ way.setTag("country1", countries[0]);
+ way.setTag("country2", countries[0]);
}
}
}
@@ -139,35 +142,30 @@ public void processWay(ReaderWay way, Coordinate[] coords, HashMap.
- */
-package heigit.ors.routing.graphhopper.extensions.storages.builders;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import com.graphhopper.GraphHopper;
-import com.graphhopper.reader.ReaderWay;
-import com.graphhopper.storage.GraphExtension;
-import com.graphhopper.util.EdgeIteratorState;
-import com.graphhopper.util.Helper;
-
-import heigit.ors.routing.graphhopper.extensions.HeavyVehicleAttributes;
-import heigit.ors.routing.graphhopper.extensions.VehicleDimensionRestrictions;
-import heigit.ors.routing.graphhopper.extensions.storages.EmergencyVehicleAttributesGraphStorage;
-
-public class EmergencyVehicleGraphStorageBuilder extends AbstractGraphStorageBuilder {
- private boolean _includeRestrictions = true;
- private EmergencyVehicleAttributesGraphStorage _storage;
- private int _hgvType = 0;
- private boolean _hasRestrictionValues;
- private double[] _restrictionValues = new double[VehicleDimensionRestrictions.Count];
- private List _motorVehicleRestrictions = new ArrayList(5);
- private Set _motorVehicleRestrictedValues = new HashSet(5);
- private Pattern _patternHeight;
-
- public EmergencyVehicleGraphStorageBuilder() {
- // _motorVehicleRestrictions.addAll(Arrays.asList("motorcar", "motor_vehicle", "vehicle", "access"));
-
- // _motorVehicleRestrictedValues.add("private");
- // _motorVehicleRestrictedValues.add("no");
- // _motorVehicleRestrictedValues.add("restricted");
- // _motorVehicleRestrictedValues.add("military");
-
- //_patternHeight = Pattern.compile("(?:\\s*(\\d+)\\s*(?:feet|ft\\.|ft|'))?(?:(\\d+)\\s*(?:inches|in\\.|in|''|\"))?");
- _patternHeight = Pattern.compile("(?:\\s*(.*?)\\s*(?:feet|ft\\.|ft|'))?(?:\\s*(.*?)\\s*(?:inches|in\\.|in|''|\"))?");
- }
-
- public GraphExtension init(GraphHopper graphhopper) throws Exception {
- if (_storage != null)
- throw new Exception("GraphStorageBuilder has been already initialized.");
-
- if (_parameters != null) {
- String value = _parameters.get("restrictions");
- if (!Helper.isEmpty(value))
- _includeRestrictions = Boolean.parseBoolean(value);
- }
-
- _storage = new EmergencyVehicleAttributesGraphStorage(_includeRestrictions);
-
- return _storage;
- }
-
- @Override
- public void processWay(ReaderWay way) {
-
- _hgvType = 0;
-
- if (_hasRestrictionValues) {
- _restrictionValues[0] = 0.0;
- _restrictionValues[1] = 0.0;
- _restrictionValues[2] = 0.0;
- _restrictionValues[3] = 0.0;
- _restrictionValues[4] = 0.0;
-
- _hasRestrictionValues = false;
- }
-
- boolean hasHighway = way.hasTag("highway");
- if (hasHighway && way.hasTag(_motorVehicleRestrictions, _motorVehicleRestrictedValues)) {// set to 0
- _hgvType |= 0;
- // _hgvType |= HeavyVehicleAttributes.BUS;
- // _hgvType |= HeavyVehicleAttributes.AGRICULTURE;
- // _hgvType |= HeavyVehicleAttributes.FORESTRY;
- // _hgvType |= HeavyVehicleAttributes.DELIVERY;
- // _hgvType |= HeavyVehicleAttributes.GOODS;
- // _hgvType |= HeavyVehicleAttributes.HGV;
- }
-
- java.util.Iterator> it = way.getProperties();
-
- while (it.hasNext()) {
- Map.Entry pairs = it.next();
- String key = pairs.getKey();
- String value = pairs.getValue().toString();
-
- if (hasHighway) {
- if (key.equals("highway")) {
- if (value.equals("motorway") || value.equals("motorway_link")) {
- } else if (value.equals("steps")) {
- } else if ("track".equals(value)) {
- String tracktype = way.getTag("tracktype");
- if (tracktype != null && (
- tracktype.equals("grade1") || tracktype.equals("grade2") ||
- tracktype.equals("grade3") || tracktype.equals("grade4") ||
- tracktype.equals("grade5"))
- ) {
- _hgvType |= HeavyVehicleAttributes.AGRICULTURE;
- _hgvType |= HeavyVehicleAttributes.FORESTRY;
- }
- }
-
- }
- /*
- * todo borders
- */
- else {
- if (_includeRestrictions) {
- int valueIndex = -1;
-
- if (key.equals("maxheight")) {
- valueIndex = VehicleDimensionRestrictions.MaxHeight;
- } else if (key.equals("maxweight")) {
- valueIndex = VehicleDimensionRestrictions.MaxWeight;
- } else if (key.equals("maxweight:hgv")) {
- valueIndex = VehicleDimensionRestrictions.MaxWeight;
- } else if (key.equals("maxwidth")) {
- valueIndex = VehicleDimensionRestrictions.MaxWidth;
- } else if (key.equals("maxlength")) {
- valueIndex = VehicleDimensionRestrictions.MaxLength;
- } else if (key.equals("maxlength:hgv")) {
- valueIndex = VehicleDimensionRestrictions.MaxLength;
- } else if (key.equals("maxaxleload")) {
- valueIndex = VehicleDimensionRestrictions.MaxAxleLoad;
- }
-
- if (valueIndex >= 0 && !("none".equals(value) || "default".equals(value))) {
- if (valueIndex == VehicleDimensionRestrictions.MaxWeight || valueIndex == VehicleDimensionRestrictions.MaxAxleLoad) {
- if (value.contains("t")) {
- value = value.replace('t', ' ');
- } else if (value.contains("lbs")) {
- value = value.replace("lbs", " ");
- value = Double.toString(Double.parseDouble(value) / 2204.622);
- }
- } else {
- if (value.contains("m")) {
- value = value.replace('m', ' ');
- } else /*if (value.contains("'"))*/{
- // MARQ24: why the heck we only make use of our fancy RegEx for height
- // parsing - IF the string contains a ' ?!
- Matcher m = _patternHeight.matcher(value);
- if (m.matches() && m.lookingAt()) {
- double feet = Double.parseDouble(m.group(1));
- double inches = 0;
- if (m.groupCount() > 1 && m.group(2) != null) {
- inches = Double.parseDouble(m.group(2));
- }
- // MARQ24: n feet * 0.3048 = feet 2 meter - ok fine... BUT
- // x inches * 0.0254 * y feet - this does not make much sense to me...
- // double newValue = feet * 0.3048 + inches * 0.0254 * feet;
- double newValue = feet * 0.3048 + inches * 0.0254;
- value = Double.toString(newValue);
- }
- }
- }
-
- // MARQ24: FIXME: Here we can get a "NumberFormatException" and then the complete
- // iterator will stop (no additional propertis of the way will be processed!
- _restrictionValues[valueIndex] = Double.parseDouble(value);
- _hasRestrictionValues = true;
- }
- }
-
-
- // String hgvTag = getHeavyVehicleValue(key, "hgv", value); //key.equals("hgv") ? value : null;
- // String goodsTag = getHeavyVehicleValue(key, "goods", value); // key.equals("goods") ? value : null;
- // String busTag = getHeavyVehicleValue(key, "bus", value); //key.equals("bus") ? value : null;
- // String agriculturalTag = getHeavyVehicleValue(key, "agricultural", value); //key.equals("agricultural") ? value : null;
- // String forestryTag = getHeavyVehicleValue(key, "forestry", value); // key.equals("forestry") ? value : null;
- // String deliveryTag = getHeavyVehicleValue(key, "delivery", value); //key.equals("delivery") ? value : null;
-
- // String accessTag = key.equals("access") ? value : null;
-
- // if (Helper.isEmpty(accessTag)) {
- // if ("agricultural".equals(accessTag))
- // agriculturalTag = "yes";
- // else if ("forestry".equals(accessTag))
- // forestryTag = "yes";
- // else if ("bus".equals(accessTag))
- // busTag = "yes";
- // }
-
- // String motorVehicle = key.equals("motor_vehicle") ? value : null;
- // if (motorVehicle == null)
- // motorVehicle = key.equals("motorcar") ? value : null;
-
- // if (motorVehicle != null) {
- // if ("agricultural".equals(motorVehicle))
- // agriculturalTag = "yes";
- // else if ("forestry".equals(motorVehicle))
- // forestryTag = "yes";
- // else if ("delivery".equals(motorVehicle))
- // deliveryTag = "yes";
-
- // //if ("destination".equals(motorVehicle))
- // // heavyVehicleFlag |= HeavyVehicleAttributes.Destination;
- // }
-
- // if (goodsTag != null) {
- // if ("no".equals(goodsTag))
- // _hgvType |= HeavyVehicleAttributes.GOODS;
- // else if ("yes".equals(busTag))
- // _hgvType &= ~HeavyVehicleAttributes.GOODS;
- // else if ("destination".equals(goodsTag))
- // {
- // _hgvType |= HeavyVehicleAttributes.GOODS;
- // _hgvDestination |= HeavyVehicleAttributes.GOODS;//(1 << (HeavyVehicleAttributes.Goods >> 1));
- // }
- // }
-
- // if (hgvTag != null) {
- // if ("no".equals(hgvTag))
- // _hgvType |= HeavyVehicleAttributes.HGV;
- // else if ("yes".equals(busTag))
- // _hgvType &= ~HeavyVehicleAttributes.HGV;
- // else if ("destination".equals(hgvTag))
- // {
- // _hgvType |= HeavyVehicleAttributes.HGV;
- // _hgvDestination |= HeavyVehicleAttributes.HGV;// (1 << (HeavyVehicleAttributes.Hgv >> 1));
- // }
- // }
-
- // if (busTag != null) {
- // if ("no".equals(busTag))
- // _hgvType |= HeavyVehicleAttributes.BUS;
- // else if ("yes".equals(busTag))
- // _hgvType &= ~HeavyVehicleAttributes.BUS;
- // else if ("destination".equals(busTag))
- // {
- // _hgvType |= HeavyVehicleAttributes.BUS;
- // _hgvDestination |= HeavyVehicleAttributes.BUS; //(1 << (HeavyVehicleAttributes.Bus >> 1));
- // }
- // }
-
- // if (agriculturalTag != null) {
- // if ("no".equals(agriculturalTag))
- // _hgvType |= HeavyVehicleAttributes.AGRICULTURE;
- // else if ("yes".equals(busTag))
- // _hgvType &= ~HeavyVehicleAttributes.AGRICULTURE;
- // else if ("destination".equals(agriculturalTag))
- // {
- // _hgvType |= HeavyVehicleAttributes.AGRICULTURE;
- // _hgvDestination |= HeavyVehicleAttributes.AGRICULTURE;// (1 << (HeavyVehicleAttributes.Agricultural >> 1));
- // }
- // } else
-
- // if (forestryTag != null) {
- // if ("no".equals(forestryTag))
- // _hgvType |= HeavyVehicleAttributes.FORESTRY;
- // else if ("yes".equals(busTag))
- // _hgvType &= ~HeavyVehicleAttributes.FORESTRY;
- // else if ("destination".equals(forestryTag))
- // {
- // _hgvType |= HeavyVehicleAttributes.FORESTRY;
- // _hgvDestination |= HeavyVehicleAttributes.FORESTRY;//(1 << (HeavyVehicleAttributes.Forestry >> 1));
- // }
- // }
-
- // if (deliveryTag != null) {
- // if ("no".equals(deliveryTag))
- // _hgvType |= HeavyVehicleAttributes.DELIVERY;
- // else if ("yes".equals(busTag))
- // _hgvType &= ~HeavyVehicleAttributes.DELIVERY;
- // else if ("destination".equals(deliveryTag) || "delivery".equals(deliveryTag) )
- // {
- // _hgvType |= HeavyVehicleAttributes.DELIVERY;
- // _hgvDestination |= HeavyVehicleAttributes.DELIVERY; //(1 << (HeavyVehicleAttributes.Delivery >> 1));
- // }
- // }
-
- // String hazmatTag = key.equals("hazmat") ? value : null;
- // if ("no".equals(hazmatTag)) {
- // _hgvType |= HeavyVehicleAttributes.HAZMAT;
- // }
-
- // (access=no) + access:conditional=delivery @
- // (07:00-11:00); customer @ (07:00-17:00)
- }
- }
- }
- }
-
- @Override
- public void processEdge(ReaderWay way, EdgeIteratorState edge) {
- //if (_hgvType > HeavyVehicleAttributes.UNKNOWN || _hgvDestination > 0 || _hasRestrictionValues)
- {
- if (_hasRestrictionValues)
- _storage.setEdgeValue(edge.getEdge(), _hgvType, 0, _restrictionValues);
- else
- _storage.setEdgeValue(edge.getEdge(), _hgvType, 0, null);
- }
- }
-
- @Override
- public String getName() {
- return "EmergencyVehicle";
- }
-}
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/HeavyVehicleGraphStorageBuilder.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/HeavyVehicleGraphStorageBuilder.java
index f8b60ef9dc..16d46e4894 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/HeavyVehicleGraphStorageBuilder.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/HeavyVehicleGraphStorageBuilder.java
@@ -223,15 +223,8 @@ else if (key.equals("hazmat") && "no".equals(value)) {
}
}
- public void processEdge(ReaderWay way, EdgeIteratorState edge)
- {
- if (_hgvType > HeavyVehicleAttributes.UNKNOWN || _hgvDestination > 0 || _hasRestrictionValues)
- {
- if (_hasRestrictionValues)
- _storage.setEdgeValue(edge.getEdge(), _hgvType, _hgvDestination, _restrictionValues);
- else
- _storage.setEdgeValue(edge.getEdge(), _hgvType, _hgvDestination, null);
- }
+ public void processEdge(ReaderWay way, EdgeIteratorState edge) {
+ _storage.setEdgeValue(edge.getEdge(), _hgvType, _hgvDestination, _restrictionValues);
}
private String getHeavyVehicleValue(String key, String hv, String value) {
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/RoadAccessRestrictionsGraphStorageBuilder.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/RoadAccessRestrictionsGraphStorageBuilder.java
index f023eb58e3..50625349b0 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/RoadAccessRestrictionsGraphStorageBuilder.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/RoadAccessRestrictionsGraphStorageBuilder.java
@@ -253,8 +253,7 @@ private boolean isAccessAllowed(ReaderWay way, String tagName) {
}
public void processEdge(ReaderWay way, EdgeIteratorState edge) {
- if (hasRestrictions)
- storage.setEdgeValue(edge.getEdge(), restrictions);
+ storage.setEdgeValue(edge.getEdge(), restrictions);
}
public final int getRestrictions() {
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/WayCategoryGraphStorageBuilder.java b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/WayCategoryGraphStorageBuilder.java
index f91142cb42..6083533764 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/WayCategoryGraphStorageBuilder.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/graphhopper/extensions/storages/builders/WayCategoryGraphStorageBuilder.java
@@ -79,11 +79,9 @@ else if (("ford".equals(key) && value.equals("yes")))
}
}
}
-
- public void processEdge(ReaderWay way, EdgeIteratorState edge)
- {
- if (_wayType > 0)
- _storage.setEdgeValue(edge.getEdge(), _wayType);
+
+ public void processEdge(ReaderWay way, EdgeIteratorState edge) {
+ _storage.setEdgeValue(edge.getEdge(), _wayType);
}
private boolean isFerryRoute(ReaderWay way) {
diff --git a/openrouteservice/src/main/java/heigit/ors/routing/pathprocessors/ExtraInfoProcessor.java b/openrouteservice/src/main/java/heigit/ors/routing/pathprocessors/ExtraInfoProcessor.java
index 0480db94f6..cdde23b938 100644
--- a/openrouteservice/src/main/java/heigit/ors/routing/pathprocessors/ExtraInfoProcessor.java
+++ b/openrouteservice/src/main/java/heigit/ors/routing/pathprocessors/ExtraInfoProcessor.java
@@ -22,17 +22,36 @@
import com.graphhopper.storage.GraphExtension;
import com.graphhopper.util.EdgeIteratorState;
import com.graphhopper.util.PointList;
-import heigit.ors.routing.*;
+import com.vividsolutions.jts.geom.Coordinate;
+import heigit.ors.routing.RouteExtraInfo;
+import heigit.ors.routing.RouteExtraInfoFlag;
+import heigit.ors.routing.RoutingProfileType;
+import heigit.ors.routing.RoutingRequest;
import heigit.ors.routing.graphhopper.extensions.ORSGraphHopper;
-import heigit.ors.routing.graphhopper.extensions.storages.*;
+import heigit.ors.routing.graphhopper.extensions.reader.borders.CountryBordersPolygon;
+import heigit.ors.routing.graphhopper.extensions.reader.borders.CountryBordersReader;
+import heigit.ors.routing.graphhopper.extensions.storages.BordersGraphStorage;
+import heigit.ors.routing.graphhopper.extensions.storages.GraphStorageUtils;
+import heigit.ors.routing.graphhopper.extensions.storages.GreenIndexGraphStorage;
+import heigit.ors.routing.graphhopper.extensions.storages.HillIndexGraphStorage;
+import heigit.ors.routing.graphhopper.extensions.storages.NoiseIndexGraphStorage;
+import heigit.ors.routing.graphhopper.extensions.storages.OsmIdGraphStorage;
+import heigit.ors.routing.graphhopper.extensions.storages.RoadAccessRestrictionsGraphStorage;
+import heigit.ors.routing.graphhopper.extensions.storages.TollwaysGraphStorage;
+import heigit.ors.routing.graphhopper.extensions.storages.TrailDifficultyScaleGraphStorage;
+import heigit.ors.routing.graphhopper.extensions.storages.WarningGraphExtension;
+import heigit.ors.routing.graphhopper.extensions.storages.WayCategoryGraphStorage;
+import heigit.ors.routing.graphhopper.extensions.storages.WaySurfaceTypeGraphStorage;
import heigit.ors.routing.util.ElevationSmoother;
import heigit.ors.routing.util.extrainfobuilders.RouteExtraInfoBuilder;
import heigit.ors.routing.util.extrainfobuilders.SimpleRouteExtraInfoBuilder;
import heigit.ors.routing.util.extrainfobuilders.SteepnessExtraInfoBuilder;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
public class ExtraInfoProcessor extends PathProcessor {
+
private WaySurfaceTypeGraphStorage _extWaySurface;
private WayCategoryGraphStorage _extWayCategory;
private GreenIndexGraphStorage _extGreenIndex;
@@ -42,7 +61,8 @@ public class ExtraInfoProcessor extends PathProcessor {
private HillIndexGraphStorage _extHillIndex;
private OsmIdGraphStorage _extOsmId;
private RoadAccessRestrictionsGraphStorage _extRoadAccessRestrictions;
-
+ private BordersGraphStorage _extCountryTraversalInfo;
+
private RouteExtraInfo _surfaceInfo;
private RouteExtraInfoBuilder _surfaceInfoBuilder;
@@ -80,6 +100,9 @@ public class ExtraInfoProcessor extends PathProcessor {
private RouteExtraInfo _roadAccessRestrictionsInfo;
private RouteExtraInfoBuilder _roadAccessRestrictionsBuilder;
+ private RouteExtraInfo _countryTraversalInfo;
+ private RouteExtraInfoBuilder _countryTraversalBuilder;
+
private List warningExtensions;
private int _profileType = RoutingProfileType.UNKNOWN;
@@ -88,6 +111,13 @@ public class ExtraInfoProcessor extends PathProcessor {
private byte[] buffer;
private boolean _lastSegment;
+ private CountryBordersReader cbreader;
+
+ public ExtraInfoProcessor(ORSGraphHopper graphhopper, RoutingRequest req, CountryBordersReader cbReader) throws Exception {
+ this(graphhopper, req);
+ this.cbreader = cbReader;
+ }
+
public ExtraInfoProcessor(ORSGraphHopper graphHopper, RoutingRequest req) throws Exception
{
_profileType = req.getSearchParameters().getProfileType();
@@ -205,6 +235,13 @@ public ExtraInfoProcessor(ORSGraphHopper graphHopper, RoutingRequest req) throws
_roadAccessRestrictionsBuilder = new SimpleRouteExtraInfoBuilder(_roadAccessRestrictionsInfo);
}
+ if (includeExtraInfo(extraInfo, RouteExtraInfoFlag.CountryInfo)) {
+ _extCountryTraversalInfo = GraphStorageUtils.getGraphExtension(graphHopper.getGraphHopperStorage(), BordersGraphStorage.class);
+ if (_extCountryTraversalInfo != null) {
+ _countryTraversalInfo = new RouteExtraInfo("countryinfo", _extCountryTraversalInfo);
+ _countryTraversalBuilder = new SimpleRouteExtraInfoBuilder(_countryTraversalInfo);
+ }
+ }
buffer = new byte[4];
}
@@ -276,6 +313,8 @@ public List getExtras()
extras.add(_osmIdInfo);
if (_roadAccessRestrictionsInfo != null)
extras.add(_roadAccessRestrictionsInfo);
+ if (_countryTraversalInfo != null)
+ extras.add(_countryTraversalInfo);
return extras;
}
@@ -283,6 +322,25 @@ public List getExtras()
public void processEdge(EdgeIteratorState edge, boolean isLastEdge, PointList geom) {
double dist = edge.getDistance();
+ // TODO Add extra info for crossed countries
+ if (_extCountryTraversalInfo != null && cbreader != null) {
+ short country1 = _extCountryTraversalInfo.getEdgeValue(EdgeIteratorStateHelper.getOriginalEdge(edge), BordersGraphStorage.Property.START);
+ short country2 = _extCountryTraversalInfo.getEdgeValue(EdgeIteratorStateHelper.getOriginalEdge(edge), BordersGraphStorage.Property.END);
+ // This check will correct the countries of an edge if the starting coordinate of the route lies in a different country than the start of the edge.
+ if (country1 != country2 && geom.getSize() > 0) {
+ Coordinate coordinate = new Coordinate();
+ coordinate.x = geom.getLon(0);
+ coordinate.y = geom.getLat(0);
+ CountryBordersPolygon[] countries = cbreader.getCountry(coordinate);
+ if (countries.length >= 1) {
+ country1 = Short.parseShort(cbreader.getId(cbreader.getCountry(coordinate)[0].getName()));
+ }
+ }
+ if (_countryTraversalBuilder != null && country1 != 0) {
+ _countryTraversalBuilder.addSegment(country1, country1, geom, dist, isLastEdge && _lastSegment);
+ }
+ }
+
if (_extWaySurface != null && _wayTypeInfo != null || _surfaceInfo != null)
{
WaySurfaceDescription wsd = _extWaySurface.getEdgeValue(EdgeIteratorStateHelper.getOriginalEdge(edge), buffer);
diff --git a/openrouteservice/src/main/java/heigit/ors/services/isochrones/requestprocessors/json/JsonIsochronesRequestProcessor.java b/openrouteservice/src/main/java/heigit/ors/services/isochrones/requestprocessors/json/JsonIsochronesRequestProcessor.java
index 4f0dd429ff..70be13b293 100644
--- a/openrouteservice/src/main/java/heigit/ors/services/isochrones/requestprocessors/json/JsonIsochronesRequestProcessor.java
+++ b/openrouteservice/src/main/java/heigit/ors/services/isochrones/requestprocessors/json/JsonIsochronesRequestProcessor.java
@@ -163,7 +163,7 @@ private void writeResponse(HttpServletResponse response, IsochroneRequest reques
//if (includeReachFactor && traveller.getRangeType() == TravelRangeType.Time) {
- // double r = isoLine.getMaxRadius(units);
+ // double r = isoLine.getMeanRadius(units);
// double maxArea = Math.PI * r * r;
// jProperties.put("reachfactor", FormatUtility.roundToDecimals(area / maxArea, 4));
diff --git a/openrouteservice/src/main/java/heigit/ors/services/optimization/OptimizationServiceServlet.java b/openrouteservice/src/main/java/heigit/ors/services/optimization/OptimizationServiceServlet.java
deleted file mode 100644
index 2086b20b1f..0000000000
--- a/openrouteservice/src/main/java/heigit/ors/services/optimization/OptimizationServiceServlet.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/* This file is part of Openrouteservice.
- *
- * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
- * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
-
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU Lesser General Public License for more details.
-
- * You should have received a copy of the GNU Lesser General Public License along with this library;
- * if not, see .
- */
-package heigit.ors.services.optimization;
-
-import javax.servlet.*;
-import javax.servlet.http.*;
-
-import heigit.ors.services.optimization.requestprocessors.OptimizationServiceRequestProcessorFactory;
-import heigit.ors.servlet.http.AbstractHttpRequestProcessor;
-import heigit.ors.servlet.http.BaseHttpServlet;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-@Deprecated
-@RestController
-@RequestMapping("/optimized_routes")
-public class OptimizationServiceServlet extends BaseHttpServlet {
- /** Serial Version UID */
- private static final long serialVersionUID = 19433489527745L;
-
- public void init() throws ServletException {
- }
-
- public void destroy() {
-
- }
-
- @PostMapping
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
- try
- {
- AbstractHttpRequestProcessor reqProcessor = OptimizationServiceRequestProcessorFactory.createProcessor(request);
- reqProcessor.process(response);
- reqProcessor.destroy();
- }
- catch (Exception ex) {
- writeError(response, ex);
- }
- }
-
- @GetMapping
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
- try
- {
- AbstractHttpRequestProcessor reqProcessor = OptimizationServiceRequestProcessorFactory.createProcessor(request);
- reqProcessor.process(response);
- reqProcessor.destroy();
- }
- catch (Exception ex) {
- writeError(response, ex);
- }
- }
-}
diff --git a/openrouteservice/src/main/java/heigit/ors/services/optimization/OptimizationServiceSettings.java b/openrouteservice/src/main/java/heigit/ors/services/optimization/OptimizationServiceSettings.java
deleted file mode 100644
index de558a171c..0000000000
--- a/openrouteservice/src/main/java/heigit/ors/services/optimization/OptimizationServiceSettings.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/* This file is part of Openrouteservice.
- *
- * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
- * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
-
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU Lesser General Public License for more details.
-
- * You should have received a copy of the GNU Lesser General Public License along with this library;
- * if not, see .
- */
-package heigit.ors.services.optimization;
-
-import java.util.Map;
-
-import heigit.ors.config.AppConfig;
-
-public class OptimizationServiceSettings {
- private static boolean enabled = true;
- private static int maximumLocations = 100;
- private static String solverName = "default";
- private static Map solverOptions;
- private static String attribution = "";
- private static AppConfig _config;
-
- static
- {
- _config = AppConfig.Global();
- init(_config);
- }
-
- public static void loadFromFile(String path)
- {
- _config = new AppConfig(path);
-
- init(_config);
- }
-
- private static void init(AppConfig config)
- {
- String value = config.getServiceParameter("optimization", "enabled");
- if (value != null)
- enabled = Boolean.parseBoolean(value);
-
- value = AppConfig.Global().getServiceParameter("optimization", "maximum_locations");
- if (value != null)
- maximumLocations = Math.max(1, Integer.parseInt(value));
-
- value = AppConfig.Global().getServiceParameter("optimization", "solver_name");
- if (value != null)
- solverName = value;
-
- value = AppConfig.Global().getServiceParameter("optimization", "solver_options");
- if (value != null)
- solverOptions = _config.getServiceParametersMap("optimization", "solver_options", false);
-
- value = config.getServiceParameter("optimization", "attribution");
- if (value != null)
- attribution = value;
- }
-
- public static boolean getEnabled()
- {
- return enabled;
- }
-
- public static String getSolverName() {
- return solverName;
- }
-
- public static Map getSolverOptions()
- {
- return solverOptions;
- }
-
- public static int getMaximumLocations() {
- return maximumLocations;
- }
-
- public static String getAttribution() {
- return attribution;
- }
-}
diff --git a/openrouteservice/src/main/java/heigit/ors/services/optimization/requestprocessors/OptimizationServiceRequestProcessorFactory.java b/openrouteservice/src/main/java/heigit/ors/services/optimization/requestprocessors/OptimizationServiceRequestProcessorFactory.java
deleted file mode 100644
index 36d63450ab..0000000000
--- a/openrouteservice/src/main/java/heigit/ors/services/optimization/requestprocessors/OptimizationServiceRequestProcessorFactory.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/* This file is part of Openrouteservice.
- *
- * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
- * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
-
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU Lesser General Public License for more details.
-
- * You should have received a copy of the GNU Lesser General Public License along with this library;
- * if not, see .
- */
-package heigit.ors.services.optimization.requestprocessors;
-
-import javax.servlet.http.HttpServletRequest;
-
-import heigit.ors.common.StatusCode;
-import heigit.ors.exceptions.StatusCodeException;
-import heigit.ors.exceptions.UnknownParameterValueException;
-import heigit.ors.optimization.OptimizationErrorCodes;
-import heigit.ors.routing.RoutingProfileManagerStatus;
-import heigit.ors.services.matrix.MatrixServiceSettings;
-import heigit.ors.services.optimization.OptimizationServiceSettings;
-import heigit.ors.services.optimization.requestprocessors.json.JsonOptimizationRequestProcessor;
-import heigit.ors.servlet.http.AbstractHttpRequestProcessor;
-
-import com.graphhopper.util.Helper;
-
-public class OptimizationServiceRequestProcessorFactory {
-
- public static AbstractHttpRequestProcessor createProcessor(HttpServletRequest request) throws Exception
- {
- if (!(OptimizationServiceSettings.getEnabled() && MatrixServiceSettings.getEnabled()))
- throw new StatusCodeException(StatusCode.SERVICE_UNAVAILABLE, OptimizationErrorCodes.UNKNOWN, "Optimizaiton service is not enabled.");
-
- if (!RoutingProfileManagerStatus.isReady())
- throw new StatusCodeException(StatusCode.SERVICE_UNAVAILABLE, OptimizationErrorCodes.UNKNOWN, "Optimizaiton service is not ready yet.");
-
- String formatParam = request.getParameter("format");
-
- if (Helper.isEmpty(formatParam))
- formatParam = "json";
-
- if (formatParam.equalsIgnoreCase("json"))
- return new JsonOptimizationRequestProcessor(request);
- else
- throw new UnknownParameterValueException(OptimizationErrorCodes.INVALID_PARAMETER_VALUE, "format", formatParam);
- }
-}
diff --git a/openrouteservice/src/main/java/heigit/ors/services/optimization/requestprocessors/json/JsonOptimizationRequestParser.java b/openrouteservice/src/main/java/heigit/ors/services/optimization/requestprocessors/json/JsonOptimizationRequestParser.java
deleted file mode 100644
index eec9f19ce2..0000000000
--- a/openrouteservice/src/main/java/heigit/ors/services/optimization/requestprocessors/json/JsonOptimizationRequestParser.java
+++ /dev/null
@@ -1,255 +0,0 @@
-/* This file is part of Openrouteservice.
- *
- * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
- * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
-
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU Lesser General Public License for more details.
-
- * You should have received a copy of the GNU Lesser General Public License along with this library;
- * if not, see .
- */
-package heigit.ors.services.optimization.requestprocessors.json;
-
-import java.io.InputStream;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.json.JSONObject;
-
-import com.graphhopper.util.Helper;
-import com.vividsolutions.jts.geom.Coordinate;
-
-import heigit.ors.common.DistanceUnit;
-import heigit.ors.common.StatusCode;
-import heigit.ors.exceptions.MissingParameterException;
-import heigit.ors.exceptions.ParameterValueException;
-import heigit.ors.exceptions.StatusCodeException;
-import heigit.ors.exceptions.UnknownParameterValueException;
-import heigit.ors.localization.LocalizationManager;
-import heigit.ors.matrix.MatrixMetricsType;
-import heigit.ors.optimization.OptimizationErrorCodes;
-import heigit.ors.optimization.RouteOptimizationRequest;
-import heigit.ors.routing.RouteInstructionsFormat;
-import heigit.ors.routing.RoutingProfileType;
-import heigit.ors.util.CoordTools;
-import heigit.ors.util.DistanceUnitUtil;
-import heigit.ors.util.StreamUtility;
-
-public class JsonOptimizationRequestParser {
-
- public static RouteOptimizationRequest parseFromStream(InputStream stream) throws Exception
- {
- String body = StreamUtility.readStream(stream);
-
- if (Helper.isEmpty(body))
- throw new StatusCodeException(StatusCode.BAD_REQUEST, OptimizationErrorCodes.INVALID_JSON_FORMAT, "Unable to parse JSON document.");
-
- JSONObject json = null;
-
- try
- {
- json = new JSONObject(body);
- }
- catch(Exception ex)
- {
- throw new StatusCodeException(StatusCode.BAD_REQUEST, OptimizationErrorCodes.INVALID_JSON_FORMAT, "Unable to parse JSON document." + ex.getMessage());
- }
-
- RouteOptimizationRequest req = new RouteOptimizationRequest();
-
- String value = json.optString("id");
- if (!Helper.isEmpty(value))
- req.setId(value);
-
- throw new Exception("POST REQUEST IS NOT SUPPORTED");
-
-// return req;
- }
-
- public static RouteOptimizationRequest parseFromRequestParams(HttpServletRequest request) throws Exception
- {
- RouteOptimizationRequest req = new RouteOptimizationRequest();
-
- String value = request.getParameter("profile");
- if (!Helper.isEmpty(value))
- {
- int profileType = RoutingProfileType.getFromString(value);
- if (profileType == RoutingProfileType.UNKNOWN)
- throw new UnknownParameterValueException(OptimizationErrorCodes.INVALID_PARAMETER_VALUE, "profile", value);
- req.setProfileType(profileType);
- }
- else
- {
- throw new MissingParameterException(OptimizationErrorCodes.MISSING_PARAMETER, "profile");
- }
-
- Coordinate[] locations = null;
-
- value = request.getParameter("locations");
- if (!Helper.isEmpty(value))
- {
- try
- {
- locations = CoordTools.parse(value, "\\|", false, false);
- if (locations.length < 2)
- throw new ParameterValueException(OptimizationErrorCodes.INVALID_PARAMETER_VALUE, "locations");
-
- req.setLocations(locations);
- }
- catch(NumberFormatException nfex)
- {
- throw new ParameterValueException(OptimizationErrorCodes.INVALID_PARAMETER_FORMAT, "locations");
- }
- }
- else
- {
- throw new MissingParameterException(OptimizationErrorCodes.MISSING_PARAMETER, "locations");
- }
-
- value = request.getParameter("source");
- if (!Helper.isEmpty(value))
- {
- int sourceIndex = 0;
-
- try
- {
- String paramSource = request.getParameter("source");
- if ("any".equalsIgnoreCase(paramSource))
- sourceIndex = -1;
- else
- sourceIndex = Integer.parseInt(paramSource);
- }
- catch(NumberFormatException ex)
- {
- throw new ParameterValueException(OptimizationErrorCodes.INVALID_PARAMETER_FORMAT, "source");
- }
-
- if (sourceIndex >= locations.length)
- throw new ParameterValueException(OptimizationErrorCodes.INVALID_PARAMETER_VALUE, "source");
-
- req.setSourceIndex(sourceIndex);
- }
- else
- req.setSourceIndex(-1);
-
- value = request.getParameter("destination");
- if (!Helper.isEmpty(value))
- {
- int destIndex = locations.length - 1;
-
- try
- {
- String paramSource = request.getParameter("destination");
- if ("any".equalsIgnoreCase(paramSource))
- destIndex = -1;
- else
- destIndex = Integer.parseInt(paramSource);
- }
- catch(NumberFormatException ex)
- {
- throw new ParameterValueException(OptimizationErrorCodes.INVALID_PARAMETER_FORMAT, "destination");
- }
-
- if (destIndex >= locations.length)
- throw new ParameterValueException(OptimizationErrorCodes.INVALID_PARAMETER_VALUE, "destination");
-
- req.setDestinationIndex(destIndex);
- }
- else
- req.setDestinationIndex(-1);
-
- value = request.getParameter("roundtrip");
- if (!Helper.isEmpty(value))
- {
- try
- {
- Boolean b = Boolean.parseBoolean(value);
- if (!b && !value.equalsIgnoreCase("false"))
- throw new ParameterValueException(OptimizationErrorCodes.INVALID_PARAMETER_FORMAT, "roundtrip");
- req.setRoundTrip(b);
- }
- catch(Exception ex)
- {
- throw new ParameterValueException(OptimizationErrorCodes.INVALID_PARAMETER_FORMAT, "roundtrip", value);
- }
- }
-
- if (req.isRoundTrip() && req.getDestinationIndex() > 0 && req.getSourceIndex() != req.getDestinationIndex())
- throw new ParameterValueException(OptimizationErrorCodes.INVALID_PARAMETER_VALUE, "destination");
-
- value = request.getParameter("metric");
- if (!Helper.isEmpty(value))
- {
- int metrics = MatrixMetricsType.getFromString(value);
-
- if (metrics == MatrixMetricsType.Unknown)
- throw new ParameterValueException(OptimizationErrorCodes.INVALID_PARAMETER_VALUE, "metric", value);
-
- req.setMetric(metrics);
- }
-
- value = request.getParameter("units");
- if (!Helper.isEmpty(value))
- {
- DistanceUnit units = DistanceUnitUtil.getFromString(value, DistanceUnit.Unknown);
-
- if (units == DistanceUnit.Unknown)
- throw new ParameterValueException(OptimizationErrorCodes.INVALID_PARAMETER_VALUE, "units", value);
-
- req.setUnits(units);
- }
-
- value = request.getParameter("language");
- if (!Helper.isEmpty(value))
- {
- if(!LocalizationManager.getInstance().isLanguageSupported(value))
- throw new StatusCodeException(StatusCode.BAD_REQUEST, OptimizationErrorCodes.INVALID_PARAMETER_VALUE, "Specified language '" + value + "' is not supported.");
-
- req.setLanguage(value);
- }
-
- value = request.getParameter("geometry");
- if (!Helper.isEmpty(value))
- req.setIncludeGeometry(Boolean.parseBoolean(value));
-
- value = request.getParameter("geometry_format");
- if (!Helper.isEmpty(value))
- {
- if (!("geojson".equalsIgnoreCase(value) || "polyline".equalsIgnoreCase(value) || "encodedpolyline".equalsIgnoreCase(value)))
- throw new UnknownParameterValueException(OptimizationErrorCodes.INVALID_PARAMETER_VALUE, "geometry_format", value);
-
- req.setGeometryFormat(value);
- }
-
- value = request.getParameter("geometry_simplify");
- if (!Helper.isEmpty(value))
- req.setSimplifyGeometry(Boolean.parseBoolean(value));
-
- value = request.getParameter("instructions");
- if (!Helper.isEmpty(value))
- req.setIncludeInstructions(Boolean.parseBoolean(value));
-
- value = request.getParameter("elevation");
- if (!Helper.isEmpty(value))
- req.setIncludeElevation(Boolean.parseBoolean(value));
-
- value = request.getParameter("instructions_format");
- if (!Helper.isEmpty(value))
- {
- RouteInstructionsFormat instrFormat = RouteInstructionsFormat.fromString(value);
- if (instrFormat == RouteInstructionsFormat.UNKNOWN)
- throw new UnknownParameterValueException(OptimizationErrorCodes.INVALID_PARAMETER_VALUE, "instructions_format", value);
-
- req.setInstructionsFormat(instrFormat);
- }
-
- value = request.getParameter("id");
- if (!Helper.isEmpty(value))
- req.setId(value);
-
- return req;
- }
-}
diff --git a/openrouteservice/src/main/java/heigit/ors/services/optimization/requestprocessors/json/JsonOptimizationRequestProcessor.java b/openrouteservice/src/main/java/heigit/ors/services/optimization/requestprocessors/json/JsonOptimizationRequestProcessor.java
deleted file mode 100644
index c3a88fc122..0000000000
--- a/openrouteservice/src/main/java/heigit/ors/services/optimization/requestprocessors/json/JsonOptimizationRequestProcessor.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/* This file is part of Openrouteservice.
- *
- * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
- * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
-
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU Lesser General Public License for more details.
-
- * You should have received a copy of the GNU Lesser General Public License along with this library;
- * if not, see .
- */
-package heigit.ors.services.optimization.requestprocessors.json;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.json.JSONArray;
-import org.json.JSONObject;
-
-import com.graphhopper.util.Helper;
-import com.graphhopper.util.shapes.BBox;
-
-import heigit.ors.common.StatusCode;
-import heigit.ors.config.AppConfig;
-import heigit.ors.exceptions.ParameterOutOfRangeException;
-import heigit.ors.exceptions.StatusCodeException;
-import heigit.ors.geojson.GeometryJSON;
-import heigit.ors.optimization.OptimizationErrorCodes;
-import heigit.ors.optimization.RouteOptimizationRequest;
-import heigit.ors.optimization.RouteOptimizationResult;
-import heigit.ors.routing.RouteResult;
-import heigit.ors.routing.RoutingProfileManager;
-import heigit.ors.routing.RoutingProfileType;
-import heigit.ors.routing.RoutingRequest;
-import heigit.ors.services.optimization.OptimizationServiceSettings;
-import heigit.ors.services.routing.requestprocessors.json.JsonRoutingResponseWriter;
-import heigit.ors.servlet.http.AbstractHttpRequestProcessor;
-import heigit.ors.servlet.util.ServletUtility;
-import heigit.ors.util.AppInfo;
-import heigit.ors.util.DistanceUnitUtil;
-import heigit.ors.util.FileUtility;
-
-
-public class JsonOptimizationRequestProcessor extends AbstractHttpRequestProcessor
-{
- public JsonOptimizationRequestProcessor(HttpServletRequest request) throws Exception
- {
- super(request);
- }
-
- @Override
- public void process(HttpServletResponse response) throws Exception
- {
- String reqMethod = _request.getMethod();
-
- RouteOptimizationRequest req = null;
-
- switch (reqMethod)
- {
- case "GET":
- req = JsonOptimizationRequestParser.parseFromRequestParams(_request);
- break;
- case "POST":
- req = JsonOptimizationRequestParser.parseFromStream(_request.getInputStream());
- break;
- default:
- throw new StatusCodeException(StatusCode.METHOD_NOT_ALLOWED);
- }
-
- if (req == null)
- throw new StatusCodeException(StatusCode.BAD_REQUEST, OptimizationErrorCodes.UNKNOWN, "RouteOptimizationRequest object is null.");
-
- if (OptimizationServiceSettings.getMaximumLocations() > 0 && req.getLocationsCount() > OptimizationServiceSettings.getMaximumLocations())
- throw new ParameterOutOfRangeException(OptimizationErrorCodes.PARAMETER_VALUE_EXCEEDS_MAXIMUM, "locations", Integer.toString(req.getLocationsCount()), Integer.toString(OptimizationServiceSettings.getMaximumLocations()));
-
- RouteOptimizationResult optResult = RoutingProfileManager.getInstance().computeOptimizedRoutes(req);
-
- writeResponse(response, req, optResult);
- }
-
- private void writeResponse(HttpServletResponse response, RouteOptimizationRequest request, RouteOptimizationResult optResult) throws Exception
- {
- JSONObject jResp = new JSONObject(true);
-
- RoutingRequest reqRoute = request.createRoutingRequest(optResult.getWayPoints());
-
- BBox bbox = new BBox(0, 0, 0, 0);
- JSONArray jRoutes = JsonRoutingResponseWriter.toJsonArray(reqRoute, new RouteResult[] { optResult.getRouteResult() }, bbox);
- jResp.put("routes", jRoutes);
-
- JSONArray jWayPoints = new JSONArray();
- jWayPoints.put(0, new JSONArray(optResult.getWayPoints()));
- jResp.put("way_points", jWayPoints);
-
- if (bbox != null)
- jResp.put("bbox", GeometryJSON.toJSON(bbox.minLon, bbox.minLat, bbox.maxLon, bbox.maxLat));
-
- JSONObject jQuery = new JSONObject();
-
- jQuery.put("profile", RoutingProfileType.getName(request.getProfileType()));
-
- if (request.getUnits() != null)
- jQuery.put("units", DistanceUnitUtil.toString(request.getUnits()));
-
- /*if (request.getWeightingMethod() != null)
- jQuery.put("preference", request.getWeightingMethod());*/
-
- if (request.getId() != null)
- jQuery.put("id", request.getId());
-
- JSONObject jInfo = new JSONObject(true);
- jInfo.put("service", "optimization");
- jInfo.put("engine", AppInfo.getEngineInfo());
- if (!Helper.isEmpty(OptimizationServiceSettings.getAttribution()))
- jInfo.put("attribution", OptimizationServiceSettings.getAttribution());
- jInfo.put("timestamp", System.currentTimeMillis());
-
- if (AppConfig.hasValidMD5Hash())
- jInfo.put("osm_file_md5_hash", AppConfig.getMD5Hash());
-
- jInfo.put("query", jQuery);
- jResp.put("info", jInfo);
-
- ServletUtility.write(response, jResp);
- }
-}
diff --git a/openrouteservice/src/main/resources/META-INF/services/heigit.ors.routing.graphhopper.extensions.storages.builders.GraphStorageBuilder b/openrouteservice/src/main/resources/META-INF/services/heigit.ors.routing.graphhopper.extensions.storages.builders.GraphStorageBuilder
index ef8b6d08fc..8f8fdcd311 100644
--- a/openrouteservice/src/main/resources/META-INF/services/heigit.ors.routing.graphhopper.extensions.storages.builders.GraphStorageBuilder
+++ b/openrouteservice/src/main/resources/META-INF/services/heigit.ors.routing.graphhopper.extensions.storages.builders.GraphStorageBuilder
@@ -5,8 +5,6 @@ heigit.ors.routing.graphhopper.extensions.storages.builders.HillIndexGraphStorag
heigit.ors.routing.graphhopper.extensions.storages.builders.WheelchairGraphStorageBuilder
heigit.ors.routing.graphhopper.extensions.storages.builders.GreenIndexGraphStorageBuilder
heigit.ors.routing.graphhopper.extensions.storages.builders.NoiseIndexGraphStorageBuilder
-heigit.ors.routing.graphhopper.extensions.storages.builders.EmergencyVehicleGraphStorageBuilder
-heigit.ors.routing.graphhopper.extensions.storages.builders.AccessRestrictionsGraphStorageBuilder
heigit.ors.routing.graphhopper.extensions.storages.builders.TollwaysGraphStorageBuilder
heigit.ors.routing.graphhopper.extensions.storages.builders.TrailDifficultyScaleGraphStorageBuilder
heigit.ors.routing.graphhopper.extensions.storages.builders.BordersGraphStorageBuilder
diff --git a/openrouteservice/src/main/resources/app.config.sample b/openrouteservice/src/main/resources/app.config.sample
index 96317ccd81..f3a7be00a3 100644
--- a/openrouteservice/src/main/resources/app.config.sample
+++ b/openrouteservice/src/main/resources/app.config.sample
@@ -70,7 +70,7 @@
"lm": {
"enabled": true,
"threads": 1,
- "weightings": "fastest|shortest",
+ "weightings": "fastest,shortest",
"landmarks": 16
}
}
@@ -105,15 +105,15 @@
"lm": {
"enabled": false,
"threads": 1,
- "weightings": "fastest|shortest",
+ "weightings": "fastest,shortest",
"landmarks": 16
},
"core": {
"enabled": true,
"threads": 1,
- "weightings": "fastest|shortest",
+ "weightings": "fastest,shortest",
"landmarks": 64,
- "lmsets": "highways,tollways;highways;tollways;country_193;allow_all"
+ "lmsets": "highways;allow_all"
}
}
},
@@ -162,15 +162,15 @@
"lm": {
"enabled": true,
"threads": 1,
- "weightings": "fastest|shortest",
+ "weightings": "fastest,shortest",
"landmarks": 16
},
"core": {
"enabled": true,
"threads": 1,
- "weightings": "fastest|shortest",
+ "weightings": "fastest,shortest",
"landmarks": 64,
- "lmsets": "highways,tollways;highways;tollways;country_193;allow_all"
+ "lmsets": "highways;allow_all"
}
}
},
diff --git a/openrouteservice/src/test/java/heigit/ors/api/requests/routing/APIEnumsTest.java b/openrouteservice/src/test/java/heigit/ors/api/requests/routing/APIEnumsTest.java
index ae06757194..43a566f424 100644
--- a/openrouteservice/src/test/java/heigit/ors/api/requests/routing/APIEnumsTest.java
+++ b/openrouteservice/src/test/java/heigit/ors/api/requests/routing/APIEnumsTest.java
@@ -33,6 +33,7 @@ public void testExtraInfoEnumCreation() throws ParameterValueException {
Assert.assertEquals(APIEnums.ExtraInfo.TOLLWAYS, APIEnums.ExtraInfo.forValue("tollways"));
Assert.assertEquals(APIEnums.ExtraInfo.TRAIL_DIFFICULTY, APIEnums.ExtraInfo.forValue("traildifficulty"));
Assert.assertEquals(APIEnums.ExtraInfo.OSM_ID, APIEnums.ExtraInfo.forValue("osmid"));
+ Assert.assertEquals(APIEnums.ExtraInfo.COUNTRY_INFO, APIEnums.ExtraInfo.forValue("countryinfo"));
APIEnums.ExtraInfo.forValue("invalid");
}
@@ -47,6 +48,7 @@ public void testExtraInfoEnumValue() {
Assert.assertEquals("tollways", APIEnums.ExtraInfo.TOLLWAYS.toString());
Assert.assertEquals("traildifficulty", APIEnums.ExtraInfo.TRAIL_DIFFICULTY.toString());
Assert.assertEquals("osmid", APIEnums.ExtraInfo.OSM_ID.toString());
+ Assert.assertEquals("countryinfo", APIEnums.ExtraInfo.COUNTRY_INFO.toString());
}
@Test(expected = ParameterValueException.class)
diff --git a/openrouteservice/src/test/java/heigit/ors/globalResponseProcessor/gpx/beans/XMLBuilderTest.java b/openrouteservice/src/test/java/heigit/ors/globalResponseProcessor/gpx/beans/XMLBuilderTest.java
index 8dfc973d66..23d86076f6 100644
--- a/openrouteservice/src/test/java/heigit/ors/globalResponseProcessor/gpx/beans/XMLBuilderTest.java
+++ b/openrouteservice/src/test/java/heigit/ors/globalResponseProcessor/gpx/beans/XMLBuilderTest.java
@@ -56,7 +56,7 @@ public static void setUp() throws DatatypeConfigurationException {
// set route Extensions
RteTypeExtensions rteTypeExtensions = new RteTypeExtensions();
rteTypeExtensions.setAscent(0);
- rteTypeExtensions.setAvgSpeed(0);
+ rteTypeExtensions.setAvgspeed(0);
rteTypeExtensions.setDescent(0);
rteTypeExtensions.setDistance(0);
rteTypeExtensions.setDistanceActual(0);
@@ -203,8 +203,8 @@ public void testBuild() throws JAXBException {
" 0.0\n" +
" 0.0\n" +
" 0.0\n" +
- " 0.0\n" +
- " \n" +
+ " 0.0\n" +
+ " \n" +
" \n" +
" \n" +
" \n" +
diff --git a/openrouteservice/src/test/java/heigit/ors/routing/graphhopper/extensions/flagencoders/HikingFlagEncoderTest.java b/openrouteservice/src/test/java/heigit/ors/routing/graphhopper/extensions/flagencoders/HikingFlagEncoderTest.java
new file mode 100644
index 0000000000..4c86ae1db6
--- /dev/null
+++ b/openrouteservice/src/test/java/heigit/ors/routing/graphhopper/extensions/flagencoders/HikingFlagEncoderTest.java
@@ -0,0 +1,264 @@
+/*
+ * This file is part of Openrouteservice.
+ *
+ * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with this library;
+ * if not, see .
+ */
+
+package heigit.ors.routing.graphhopper.extensions.flagencoders;
+
+import com.graphhopper.reader.ReaderRelation;
+import com.graphhopper.reader.ReaderWay;
+import com.graphhopper.routing.util.EncodingManager;
+import com.graphhopper.routing.util.PriorityCode;
+import com.graphhopper.util.PMap;
+import heigit.ors.routing.graphhopper.extensions.ORSDefaultFlagEncoderFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.TreeMap;
+
+import static org.junit.Assert.*;
+
+public class HikingFlagEncoderTest {
+ private HikingFlagEncoder flagEncoder;
+ private ReaderWay way;
+
+ public HikingFlagEncoderTest() {
+ PMap properties = new PMap();
+ ORSDefaultFlagEncoderFactory encoderFactory = new ORSDefaultFlagEncoderFactory();
+ flagEncoder = (HikingFlagEncoder)new EncodingManager(new ORSDefaultFlagEncoderFactory(), FlagEncoderNames.HIKING_ORS, 4).getEncoder(FlagEncoderNames.HIKING_ORS);
+ }
+
+ @Before
+ public void initWay() {
+ way = new ReaderWay(1);
+ }
+
+ private ReaderWay generateHikeWay() {
+ way.getTags().put("highway", "path");
+ return way;
+ }
+
+ private ReaderWay generateFerryWay() {
+ way.getTags().put("route", "ferry");
+ return way;
+ }
+
+ @Test
+ public void acceptDifficultSacScale() {
+ way = generateHikeWay();
+ way.getTags().put("sac_scale", "alpine_hiking");
+
+ assertEquals(1, flagEncoder.acceptWay(way));
+ }
+
+ @Test
+ public void noTurnRestrictions() {
+ assertFalse(flagEncoder.isTurnRestricted(1));
+ }
+
+ @Test
+ public void noTurnCost() {
+ assertEquals(0, flagEncoder.getTurnCost(1), 0.0);
+ }
+
+ @Test
+ public void allwaysNoTurnFlags() {
+ assertEquals(0.0, flagEncoder.getTurnFlags(false, 1.0), 0.0);
+ }
+
+ @Test
+ public void handleRelationTags() {
+ ReaderRelation rel = new ReaderRelation(1);
+ rel.getTags().put("route", "hiking");
+
+ rel.getTags().put("network", "iwn");
+ assertEquals(PriorityCode.BEST.getValue(), flagEncoder.handleRelationTags(rel, 0));
+ rel.getTags().put("network", "nwn");
+ assertEquals(PriorityCode.BEST.getValue(), flagEncoder.handleRelationTags(rel, 0));
+ rel.getTags().put("network", "rwn");
+ assertEquals(PriorityCode.VERY_NICE.getValue(), flagEncoder.handleRelationTags(rel, 0));
+ rel.getTags().put("network", "lwn");
+ assertEquals(PriorityCode.VERY_NICE.getValue(), flagEncoder.handleRelationTags(rel, 0));
+
+ rel.getTags().put("route","foot");rel.getTags().put("network", "iwn");
+ assertEquals(PriorityCode.BEST.getValue(), flagEncoder.handleRelationTags(rel, 0));
+ rel.getTags().put("network", "nwn");
+ assertEquals(PriorityCode.BEST.getValue(), flagEncoder.handleRelationTags(rel, 0));
+ rel.getTags().put("network", "rwn");
+ assertEquals(PriorityCode.VERY_NICE.getValue(), flagEncoder.handleRelationTags(rel, 0));
+ rel.getTags().put("network", "lwn");
+ assertEquals(PriorityCode.VERY_NICE.getValue(), flagEncoder.handleRelationTags(rel, 0));
+
+ rel.getTags().put("network", "unknown");
+ assertEquals(PriorityCode.VERY_NICE.getValue(), flagEncoder.handleRelationTags(rel, 0));
+
+ rel.getTags().put("route", "ferry");
+ assertEquals(PriorityCode.AVOID_IF_POSSIBLE.getValue(), flagEncoder.handleRelationTags(rel, 0));
+
+ }
+
+ @Test
+ public void testOldRelationValueMaintained() {
+ ReaderRelation rel = new ReaderRelation(1);
+ rel.getTags().put("route", "hiking");
+
+ rel.getTags().put("network", "rwn");
+ assertEquals(7, flagEncoder.handleRelationTags(rel, 7));
+ }
+
+ @Test
+ public void testAddPriorityFromRelation() {
+ way = generateHikeWay();
+ assertEquals(171, flagEncoder.handleWayTags(way, 1, 1));
+ }
+
+ @Test
+ public void testRejectWay() {
+ assertEquals(0, flagEncoder.handleWayTags(way, 0, 0));
+ }
+
+ @Test
+ public void testFerrySpeed() {
+ way = generateFerryWay();
+ assertEquals(555, flagEncoder.handleWayTags(way, 3, 0));
+ }
+
+ @Test
+ public void testHikingFlags() {
+ way = generateHikeWay();
+ assertEquals(811, flagEncoder.handleWayTags(way, 1, 0));
+
+ way.getTags().put("highway", "living_street");
+ assertEquals(683, flagEncoder.handleWayTags(way, 1, 0));
+ }
+
+ @Test
+ public void testDifficultHikingFlags() {
+ way = generateHikeWay();
+ way.getTags().put("sac_scale", "alpine_hiking");
+ assertEquals(787, flagEncoder.handleWayTags(way, 1, 0));
+ }
+
+ @Test
+ public void testAvoidWaysWithoutSidewalks() {
+ way.getTags().put("highway", "primary");
+ assertEquals(171, flagEncoder.handleWayTags(way, 1, 0));
+ way.getTags().put("sidewalk", "both");
+ assertEquals(555, flagEncoder.handleWayTags(way, 1, 0));
+ way.getTags().put("sidewalk", "none");
+ assertEquals(171, flagEncoder.handleWayTags(way, 1, 0));
+ }
+
+ @Test
+ public void testSafeHighwayPriorities() {
+ TreeMap priorityMap = new TreeMap<>();
+ way.getTags().put("highway", "track");
+ flagEncoder.assignSafeHighwayPriority(way, priorityMap);
+ assertEquals((Integer)PriorityCode.VERY_NICE.getValue(), priorityMap.lastEntry().getValue());
+ priorityMap.clear();
+ way.getTags().put("highway", "path");
+ flagEncoder.assignSafeHighwayPriority(way, priorityMap);
+ assertEquals((Integer)PriorityCode.VERY_NICE.getValue(), priorityMap.lastEntry().getValue());
+ priorityMap.clear();
+ way.getTags().put("highway", "footway");
+ flagEncoder.assignSafeHighwayPriority(way, priorityMap);
+ assertEquals((Integer)PriorityCode.VERY_NICE.getValue(), priorityMap.lastEntry().getValue());
+ priorityMap.clear();
+
+ way.getTags().put("highway", "living_street");
+ flagEncoder.assignSafeHighwayPriority(way, priorityMap);
+ assertEquals((Integer)PriorityCode.PREFER.getValue(), priorityMap.lastEntry().getValue());
+ priorityMap.clear();
+ }
+
+ @Test
+ public void testAcceptWayFerry() {
+ way = generateFerryWay();
+ assertEquals(3, flagEncoder.acceptWay(way));
+ }
+
+ @Test
+ public void testAcceptFootway() {
+ way = generateHikeWay();
+ way.getTags().put("foot", "yes");
+ assertEquals(1, flagEncoder.acceptWay(way));
+ way.getTags().put("foot", "designated");
+ assertEquals(1, flagEncoder.acceptWay(way));
+ way.getTags().put("foot", "official");
+ assertEquals(1, flagEncoder.acceptWay(way));
+ way.getTags().put("foot", "permissive");
+ assertEquals(1, flagEncoder.acceptWay(way));
+ }
+
+ @Test
+ public void testRejectRestrictedFootway() {
+ way = generateHikeWay();
+ way.getTags().put("foot", "no");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("foot", "private");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("foot", "restricted");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("foot", "military");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("foot", "emergency");
+ assertEquals(0, flagEncoder.acceptWay(way));
+
+ way.removeTag("foot");
+ way.getTags().put("access", "no");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("access", "private");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("access", "restricted");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("access", "military");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("access", "emergency");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ }
+
+ @Test
+ public void testAcceptSidewalks() {
+ way.getTags().put("highway", "secondary");
+ way.getTags().put("sidewalk", "both");
+ assertEquals(1, flagEncoder.acceptWay(way));
+ way.getTags().put("sidewalk", "left");
+ assertEquals(1, flagEncoder.acceptWay(way));
+ way.getTags().put("sidewalk", "right");
+ assertEquals(1, flagEncoder.acceptWay(way));
+ way.getTags().put("sidewalk", "yes");
+ assertEquals(1, flagEncoder.acceptWay(way));
+ }
+
+ @Test
+ public void testRejectMotorways() {
+ way.getTags().put("highway", "motorway");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("highway", "motorway_link");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ }
+
+ @Test
+ public void testRejectMotorRoad() {
+ way = generateHikeWay();
+ way.getTags().put("motorroad", "yes");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ }
+
+ @Test
+ public void testDefaultFords() {
+ way = generateHikeWay();
+ way.getTags().put("ford", "yes");
+ assertEquals(1, flagEncoder.acceptWay(way));
+ }
+}
diff --git a/openrouteservice/src/test/java/heigit/ors/routing/graphhopper/extensions/flagencoders/PedestrianFlagEncoderTest.java b/openrouteservice/src/test/java/heigit/ors/routing/graphhopper/extensions/flagencoders/PedestrianFlagEncoderTest.java
new file mode 100644
index 0000000000..c2571b4b2f
--- /dev/null
+++ b/openrouteservice/src/test/java/heigit/ors/routing/graphhopper/extensions/flagencoders/PedestrianFlagEncoderTest.java
@@ -0,0 +1,289 @@
+/*
+ * This file is part of Openrouteservice.
+ *
+ * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with this library;
+ * if not, see .
+ */
+
+package heigit.ors.routing.graphhopper.extensions.flagencoders;
+
+import com.graphhopper.reader.ReaderRelation;
+import com.graphhopper.reader.ReaderWay;
+import com.graphhopper.routing.util.EncodingManager;
+import com.graphhopper.routing.util.PriorityCode;
+import com.graphhopper.routing.weighting.FastestWeighting;
+import com.graphhopper.routing.weighting.PriorityWeighting;
+import com.graphhopper.routing.weighting.TurnWeighting;
+import com.graphhopper.util.PMap;
+import heigit.ors.routing.graphhopper.extensions.ORSDefaultFlagEncoderFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.TreeMap;
+
+import static org.junit.Assert.*;
+
+public class PedestrianFlagEncoderTest {
+ private PedestrianFlagEncoder flagEncoder;
+ private ReaderWay way;
+
+ public PedestrianFlagEncoderTest() {
+ flagEncoder = (PedestrianFlagEncoder)new EncodingManager(new ORSDefaultFlagEncoderFactory(), FlagEncoderNames.PEDESTRIAN_ORS, 4).getEncoder(FlagEncoderNames.PEDESTRIAN_ORS);
+ }
+
+ @Before
+ public void initWay() {
+ way = new ReaderWay(1);
+ }
+
+ private ReaderWay generatePedestrianWay() {
+ way.getTags().put("highway", "path");
+ return way;
+ }
+
+ private ReaderWay generateFerryWay() {
+ way.getTags().put("route", "ferry");
+ way.getTags().put("estimated_distance", 20000);
+ way.getTags().put("duration:seconds", "1800");
+ return way;
+ }
+
+ @Test
+ public void rejectDifficultSacScale() {
+ way = generatePedestrianWay();
+ way.getTags().put("sac_scale", "alpine_hiking");
+
+ assertEquals(0, flagEncoder.acceptWay(way));
+ }
+
+ @Test
+ public void noTurnRestrictions() {
+ assertFalse(flagEncoder.isTurnRestricted(1));
+ }
+
+ @Test
+ public void noTurnCost() {
+ assertEquals(0, flagEncoder.getTurnCost(1), 0.0);
+ }
+
+ @Test
+ public void allwaysNoTurnFlags() {
+ assertEquals(0.0, flagEncoder.getTurnFlags(false, 1.0), 0.0);
+ }
+
+ @Test
+ public void handleRelationTags() {
+ ReaderRelation rel = new ReaderRelation(1);
+
+ rel.getTags().put("route", "ferry");
+ assertEquals(PriorityCode.AVOID_IF_POSSIBLE.getValue(), flagEncoder.handleRelationTags(rel, 0));
+ }
+
+ @Test
+ public void testRejectWay() {
+ assertEquals(0, flagEncoder.handleWayTags(way, 0, 0));
+ }
+
+ @Test
+ public void testFerryFlags() {
+ way = generateFerryWay();
+ assertEquals(635, flagEncoder.handleWayTags(way, 3, 0));
+ }
+
+ @Test
+ public void testPlatformFlags() {
+ way.getTags().put("railway", "platform");
+ assertEquals(1, flagEncoder.acceptWay(way));
+
+ way.getTags().put("railway", "track");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ }
+
+ @Test
+ public void testPierFlags() {
+ way.getTags().put("man_made", "pier");
+ assertEquals(1, flagEncoder.acceptWay(way));
+
+ way.getTags().put("man_made", "not_a_pier");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ }
+
+ @Test
+ public void testHikingFlags() {
+ way = generatePedestrianWay();
+ way.getTags().put("sac_scale", "hiking");
+ assertEquals(683, flagEncoder.handleWayTags(way, 1, 0));
+
+ way.getTags().put("highway", "living_street");
+ assertEquals(683, flagEncoder.handleWayTags(way, 1, 0));
+ }
+
+ @Test
+ public void testDesignatedFootwayPriority() {
+ way.getTags().put("highway", "secondary");
+ assertEquals(299, flagEncoder.handleWayTags(way, 1, 0));
+
+ way.getTags().put("foot", "designated");
+ assertEquals(683, flagEncoder.handleWayTags(way, 1, 0));
+ }
+
+ @Test
+ public void testAvoidWaysWithoutSidewalks() {
+ way.getTags().put("highway", "primary");
+ assertEquals(171, flagEncoder.handleWayTags(way, 1, 0));
+ way.getTags().put("sidewalk", "both");
+ assertEquals(555, flagEncoder.handleWayTags(way, 1, 0));
+ way.getTags().put("sidewalk", "none");
+ assertEquals(171, flagEncoder.handleWayTags(way, 1, 0));
+ }
+
+ @Test
+ public void testAcceptWayFerry() {
+ way = generateFerryWay();
+ assertEquals(3, flagEncoder.acceptWay(way));
+ }
+
+ @Test
+ public void testAcceptFootway() {
+ way = generatePedestrianWay();
+ way.getTags().put("foot", "yes");
+ assertEquals(1, flagEncoder.acceptWay(way));
+ way.getTags().put("foot", "designated");
+ assertEquals(1, flagEncoder.acceptWay(way));
+ way.getTags().put("foot", "official");
+ assertEquals(1, flagEncoder.acceptWay(way));
+ way.getTags().put("foot", "permissive");
+ assertEquals(1, flagEncoder.acceptWay(way));
+ }
+
+ @Test
+ public void testRejectRestrictedFootway() {
+ way = generatePedestrianWay();
+ way.getTags().put("foot", "no");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("foot", "private");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("foot", "restricted");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("foot", "military");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("foot", "emergency");
+ assertEquals(0, flagEncoder.acceptWay(way));
+
+ way.removeTag("foot");
+ way.getTags().put("access", "no");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("access", "private");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("access", "restricted");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("access", "military");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("access", "emergency");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ }
+
+ @Test
+ public void testAcceptSidewalks() {
+ way.getTags().put("highway", "secondary");
+ way.getTags().put("sidewalk", "both");
+ assertEquals(1, flagEncoder.acceptWay(way));
+ way.getTags().put("sidewalk", "left");
+ assertEquals(1, flagEncoder.acceptWay(way));
+ way.getTags().put("sidewalk", "right");
+ assertEquals(1, flagEncoder.acceptWay(way));
+ way.getTags().put("sidewalk", "yes");
+ assertEquals(1, flagEncoder.acceptWay(way));
+ }
+
+ @Test
+ public void testRejectMotorways() {
+ way.getTags().put("highway", "motorway");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ way.getTags().put("highway", "motorway_link");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ }
+
+ @Test
+ public void testRejectMotorRoad() {
+ way = generatePedestrianWay();
+ way.getTags().put("motorroad", "yes");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ }
+
+ @Test
+ public void testDefaultFords() {
+ way = generatePedestrianWay();
+ way.getTags().put("ford", "yes");
+ assertEquals(0, flagEncoder.acceptWay(way));
+ }
+
+ @Test
+ public void testTunnelValues() {
+ TreeMap priorityMap = new TreeMap<>();
+ way.getTags().put("highway", "residential");
+ way.getTags().put("tunnel", "yes");
+ way.getTags().put("sidewalk", "no");
+ flagEncoder.assignSafeHighwayPriority(way, priorityMap);
+ assertEquals((Integer)PriorityCode.AVOID_IF_POSSIBLE.getValue(), priorityMap.lastEntry().getValue());
+
+ way.getTags().put("sidewalk", "both");
+ flagEncoder.assignSafeHighwayPriority(way, priorityMap);
+ assertEquals((Integer)PriorityCode.UNCHANGED.getValue(), priorityMap.lastEntry().getValue());
+ }
+
+ @Test
+ public void testBicyclePathPriority(){
+ way.getTags().put("highway", "path");
+ assertEquals(683, flagEncoder.handleWayTags(way, 1, 0));
+ way.getTags().put("bicycle", "official");
+ assertEquals(427, flagEncoder.handleWayTags(way, 1, 0));
+ way.getTags().put("bicycle", "designated");
+ assertEquals(427, flagEncoder.handleWayTags(way, 1, 0));
+ way.getTags().put("bicycle", "permissive");
+ assertEquals(683, flagEncoder.handleWayTags(way, 1, 0));
+ }
+
+ @Test
+ public void testSpeed() {
+ assertEquals(5.0, flagEncoder.getSpeed(683), 0.0);
+ assertEquals(20.0, flagEncoder.getSpeed(635), 0.0);
+ }
+
+ @Test
+ public void testSupports() {
+ assertTrue(flagEncoder.supports(PriorityWeighting.class));
+ assertFalse(flagEncoder.supports(TurnWeighting.class));
+ }
+
+ @Test
+ public void getWeighting() {
+ assertEquals(0.714, flagEncoder.getDouble(683, PriorityWeighting.KEY), 0.001);
+ boolean throwsError = false;
+ try {
+ // Only priority weighting allowed
+ flagEncoder.getDouble(683, 1);
+ } catch (UnsupportedOperationException e) {
+ throwsError = true;
+ }
+
+ assertTrue(throwsError);
+ }
+
+ @Test
+ public void testRoundaboutFlag() {
+ way = generatePedestrianWay();
+ way.getTags().put("junction", "roundabout");
+ assertEquals(687, flagEncoder.handleWayTags(way, 1, 0));
+ way.getTags().put("junction", "circular");
+ assertEquals(687, flagEncoder.handleWayTags(way, 1, 0));
+ }
+}
diff --git a/openrouteservice/src/test/java/heigit/ors/routing/graphhopper/extensions/storages/builders/BordersGraphStorageBuilderTest.java b/openrouteservice/src/test/java/heigit/ors/routing/graphhopper/extensions/storages/builders/BordersGraphStorageBuilderTest.java
index 1fa0624f2a..ce25af551d 100644
--- a/openrouteservice/src/test/java/heigit/ors/routing/graphhopper/extensions/storages/builders/BordersGraphStorageBuilderTest.java
+++ b/openrouteservice/src/test/java/heigit/ors/routing/graphhopper/extensions/storages/builders/BordersGraphStorageBuilderTest.java
@@ -16,7 +16,6 @@
import com.graphhopper.reader.ReaderWay;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
-import com.vividsolutions.jts.geom.LineString;
import heigit.ors.routing.graphhopper.extensions.reader.borders.CountryBordersHierarchy;
import heigit.ors.routing.graphhopper.extensions.reader.borders.CountryBordersPolygon;
import heigit.ors.routing.graphhopper.extensions.reader.borders.CountryBordersReader;
@@ -118,8 +117,8 @@ public void TestProcessWay() {
_builder.processWay(rw2, cs2, null);
- Assert.assertFalse(rw2.hasTag("country1"));
- Assert.assertFalse(rw2.hasTag("country2"));
+ Assert.assertEquals("c1", rw2.getTag("country1"));
+ Assert.assertEquals("c1", rw2.getTag("country2"));
}
/**