diff --git a/CHANGELOG.md b/CHANGELOG.md index 39d622a649..bd2bf87fea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,6 +85,7 @@ RELEASING: - schema type for parameters of type Duration ([#1504](https://github.com/GIScience/openrouteservice/pull/1504)) - Fix the max visited nodes bug for fast-isochrones ([#1538](https://github.com/GIScience/openrouteservice/pull/1538)) - adjust weighting of heat stress routing to avoid large detours +- fix isochrones snapping ([#1566](https://github.com/GIScience/openrouteservice/pull/1566)) ## [7.1.0] - 2023-06-13 ### Added diff --git a/ors-engine/src/main/java/org/heigit/ors/isochrones/GraphEdgeMapFinder.java b/ors-engine/src/main/java/org/heigit/ors/isochrones/GraphEdgeMapFinder.java index 4059284349..52011e6795 100644 --- a/ors-engine/src/main/java/org/heigit/ors/isochrones/GraphEdgeMapFinder.java +++ b/ors-engine/src/main/java/org/heigit/ors/isochrones/GraphEdgeMapFinder.java @@ -16,11 +16,14 @@ import com.carrotsearch.hppc.IntObjectMap; import com.graphhopper.GraphHopper; import com.graphhopper.routing.SPTEntry; +import com.graphhopper.routing.ev.Subnetwork; import com.graphhopper.routing.querygraph.QueryGraph; +import com.graphhopper.routing.util.DefaultSnapFilter; import com.graphhopper.routing.util.EdgeFilter; import com.graphhopper.routing.util.FlagEncoder; import com.graphhopper.routing.util.TraversalMode; import com.graphhopper.routing.weighting.FastestWeighting; +import com.graphhopper.routing.weighting.ShortestWeighting; import com.graphhopper.routing.weighting.Weighting; import com.graphhopper.storage.GraphHopperStorage; import com.graphhopper.storage.index.Snap; @@ -32,8 +35,8 @@ import org.heigit.ors.routing.algorithms.TDDijkstraCostCondition; import org.heigit.ors.routing.graphhopper.extensions.AccessibilityMap; import org.heigit.ors.routing.graphhopper.extensions.ORSEdgeFilterFactory; -import org.heigit.ors.routing.graphhopper.extensions.weighting.DistanceWeighting; import org.heigit.ors.routing.traffic.TrafficSpeedCalculator; +import org.heigit.ors.util.ProfileTools; import org.locationtech.jts.geom.Coordinate; import java.time.ZonedDateTime; @@ -47,10 +50,12 @@ private GraphEdgeMapFinder() { public static AccessibilityMap findEdgeMap(RouteSearchContext searchCntx, IsochroneSearchParameters parameters) throws Exception { GraphHopper gh = searchCntx.getGraphHopper(); FlagEncoder encoder = searchCntx.getEncoder(); + Weighting weighting = createWeighting(parameters, encoder); + String profileName = ProfileTools.makeProfileName(encoder.toString(), weighting.getName(), false); GraphHopperStorage graph = gh.getGraphHopperStorage(); - + EdgeFilter defaultSnapFilter = new DefaultSnapFilter(weighting, graph.getEncodingManager().getBooleanEncodedValue(Subnetwork.key(profileName))); ORSEdgeFilterFactory edgeFilterFactory = new ORSEdgeFilterFactory(); - EdgeFilter edgeFilter = edgeFilterFactory.createEdgeFilter(searchCntx.getProperties(), encoder, graph); + EdgeFilter edgeFilter = edgeFilterFactory.createEdgeFilter(searchCntx.getProperties(), encoder, graph, defaultSnapFilter); Coordinate loc = parameters.getLocation(); Snap res = gh.getLocationIndex().findClosest(loc.y, loc.x, edgeFilter); @@ -64,7 +69,6 @@ public static AccessibilityMap findEdgeMap(RouteSearchContext searchCntx, Isochr if (fromId == -1) throw new InternalServerException(IsochronesErrorCodes.UNKNOWN, "The closest node is null."); - Weighting weighting = createWeighting(parameters, encoder); if (parameters.isTimeDependent()) { return calculateTimeDependentAccessibilityMap(parameters, encoder, graph, edgeFilter, queryGraph, snappedPosition, fromId, weighting); @@ -114,6 +118,6 @@ private static AccessibilityMap calculateTimeDependentAccessibilityMap(Isochrone private static Weighting createWeighting(IsochroneSearchParameters parameters, FlagEncoder encoder) { return parameters.getRangeType() == TravelRangeType.TIME ? new FastestWeighting(encoder) - : new DistanceWeighting(encoder); + : new ShortestWeighting(encoder); } } diff --git a/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/DistanceWeighting.java b/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/DistanceWeighting.java deleted file mode 100644 index 0af00ac09a..0000000000 --- a/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/DistanceWeighting.java +++ /dev/null @@ -1,58 +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 org.heigit.ors.routing.graphhopper.extensions.weighting; - -import com.graphhopper.routing.util.FlagEncoder; -import com.graphhopper.routing.weighting.AbstractWeighting; -import com.graphhopper.util.EdgeIteratorState; - -public class DistanceWeighting extends AbstractWeighting { - public DistanceWeighting(FlagEncoder encoder) { - super(encoder); - } - - @Override - public double calcEdgeWeight(EdgeIteratorState edge, boolean reverse) { - double speed = flagEncoder.getAverageSpeedEnc().getDecimal(reverse, edge.getFlags()); - if (speed == 0) - return Double.POSITIVE_INFINITY; - - return edge.getDistance(); - } - - @Override - public double getMinWeight(double distance) { - return 0; - } - - @Override - public String getName() { - return "distance"; - } - - @Override - public boolean equals(Object obj) { - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - final DistanceWeighting other = (DistanceWeighting) obj; - return toString().equals(other.toString()); - } - - @Override - public int hashCode() { - return ("DistanceWeighting" + this).hashCode(); - } -}