From a8f26037d37e4840e47fe4407ea3bde666a7baec Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Tue, 17 Oct 2023 16:13:29 +0200 Subject: [PATCH] fix(fastisochrones): use correct edge filter fast-isochrones snapping (cherry picked from commit f4d9909c809813e988fb3ad3815584959957885d) --- .../fast/FastIsochroneMapBuilder.java | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/ors-engine/src/main/java/org/heigit/ors/isochrones/builders/fast/FastIsochroneMapBuilder.java b/ors-engine/src/main/java/org/heigit/ors/isochrones/builders/fast/FastIsochroneMapBuilder.java index 2da9392c87..f0ae4ef82a 100644 --- a/ors-engine/src/main/java/org/heigit/ors/isochrones/builders/fast/FastIsochroneMapBuilder.java +++ b/ors-engine/src/main/java/org/heigit/ors/isochrones/builders/fast/FastIsochroneMapBuilder.java @@ -16,18 +16,22 @@ import com.carrotsearch.hppc.IntHashSet; import com.carrotsearch.hppc.IntObjectMap; import com.carrotsearch.hppc.cursors.IntObjectCursor; +import com.graphhopper.GraphHopper; import com.graphhopper.coll.GHIntObjectHashMap; import com.graphhopper.routing.SPTEntry; +import com.graphhopper.routing.ev.Subnetwork; import com.graphhopper.routing.querygraph.QueryGraph; -import com.graphhopper.routing.util.EdgeFilter; -import com.graphhopper.routing.util.HikeFlagEncoder; -import com.graphhopper.routing.util.TraversalMode; +import com.graphhopper.routing.util.*; import com.graphhopper.routing.weighting.Weighting; import com.graphhopper.storage.Graph; import com.graphhopper.storage.GraphHopperStorage; import com.graphhopper.storage.index.Snap; import com.graphhopper.util.*; import com.graphhopper.util.shapes.GHPoint3D; +import org.heigit.ors.util.ProfileTools; +import org.locationtech.jts.geom.*; +import org.locationtech.jts.index.quadtree.Quadtree; +import org.locationtech.jts.operation.union.UnaryUnionOp; import org.apache.log4j.Logger; import org.heigit.ors.common.TravelRangeType; import org.heigit.ors.exceptions.InternalServerException; @@ -135,8 +139,15 @@ public IsochroneMap compute(IsochroneSearchParameters parameters) throws Excepti Weighting weighting = ORSWeightingFactory.createIsochroneWeighting(searchcontext, parameters.getRangeType()); Coordinate loc = parameters.getLocation(); + + FlagEncoder encoder = searchcontext.getEncoder(); + String profileName = ProfileTools.makeProfileName(encoder.toString(), weighting.getName(), false); + GraphHopper gh = searchcontext.getGraphHopper(); + GraphHopperStorage graphHopperStorage = gh.getGraphHopperStorage(); + EdgeFilter defaultSnapFilter = new DefaultSnapFilter(weighting, graphHopperStorage.getEncodingManager().getBooleanEncodedValue(Subnetwork.key(profileName))); + ORSEdgeFilterFactory edgeFilterFactory = new ORSEdgeFilterFactory(); - EdgeFilterSequence edgeFilterSequence = getEdgeFilterSequence(edgeFilterFactory); + EdgeFilterSequence edgeFilterSequence = getEdgeFilterSequence(edgeFilterFactory, defaultSnapFilter); Snap res = searchcontext.getGraphHopper().getLocationIndex().findClosest(loc.y, loc.x, edgeFilterSequence); List snaps = new ArrayList<>(1); snaps.add(res); @@ -255,9 +266,9 @@ public IsochroneMap compute(IsochroneSearchParameters parameters) throws Excepti return isochroneMap; } - private EdgeFilterSequence getEdgeFilterSequence(ORSEdgeFilterFactory edgeFilterFactory) throws Exception { + private EdgeFilterSequence getEdgeFilterSequence(ORSEdgeFilterFactory edgeFilterFactory, EdgeFilter prependFilter) throws Exception { EdgeFilterSequence edgeFilterSequence = new EdgeFilterSequence(); - EdgeFilter edgeFilter = edgeFilterFactory.createEdgeFilter(searchcontext.getProperties(), searchcontext.getEncoder(), searchcontext.getGraphHopper().getGraphHopperStorage()); + EdgeFilter edgeFilter = edgeFilterFactory.createEdgeFilter(searchcontext.getProperties(), searchcontext.getEncoder(), searchcontext.getGraphHopper().getGraphHopperStorage(), prependFilter); edgeFilterSequence.add(edgeFilter); edgeFilterSequence.add(new AvoidFeaturesEdgeFilter(AvoidFeatureFlags.FERRIES, searchcontext.getGraphHopper().getGraphHopperStorage())); return edgeFilterSequence; @@ -325,7 +336,7 @@ private List createCoordinateListFromGeometry(Geometry preprocessedGeome continue; } - LinearRing ring = ((Polygon) preprocessedGeometry.getGeometryN(j)).getExteriorRing(); + LinearRing ring = (LinearRing) ((Polygon) preprocessedGeometry.getGeometryN(j)).getExteriorRing(); for (int i = 0; i < ring.getNumPoints(); i++) { contourCoordinates.add(ring.getCoordinateN(i).y); contourCoordinates.add(ring.getCoordinateN(i).x); @@ -400,8 +411,8 @@ private void createPolyFromPoints(Set isochroneGeometries, GeometryCol try { ConcaveHullOpenSphere ch = new ConcaveHullOpenSphere(points, convertSmoothingFactorToDistance(smoothingFactor, maxRadius), false); concaveHull = ch.getConcaveHull(); - if (concaveHull instanceof Polygon polygon) { - ring = polygon.getExteriorRing(); + if (concaveHull instanceof Polygon) { + ring = (LinearRing) ((Polygon) concaveHull).getExteriorRing(); List coordinates = new ArrayList<>(ring.getNumPoints()); for (int i = 0; i < ring.getNumPoints(); i++) { coordinates.add(ring.getCoordinateN(i)); @@ -731,9 +742,9 @@ private String printCell(List coordinates, int cellId) { statement.append("{\"type\": \"Feature\",\"properties\": {\"name\": \"").append(cellId).append("\"},\"geometry\": {\"type\": \"Polygon\",\"coordinates\": [["); int i; for (i = coordinates.size() - 2; i > 0; i -= 2) { - statement.append("[").append(String.valueOf(coordinates.get(i + 1)), 0, Math.min(8, String.valueOf(coordinates.get(i + 1)).length())).append(",").append(String.valueOf(coordinates.get(i)), 0, Math.min(8, String.valueOf(coordinates.get(i)).length())).append("],"); + statement.append("[").append(String.valueOf(coordinates.get(i + 1)).substring(0, Math.min(8, String.valueOf(coordinates.get(i + 1)).length()))).append(",").append(String.valueOf(coordinates.get(i)).substring(0, Math.min(8, String.valueOf(coordinates.get(i)).length()))).append("],"); } - statement.append("[").append(String.valueOf(coordinates.get(coordinates.size() - 1)), 0, Math.min(8, String.valueOf(coordinates.get(coordinates.size() - 1)).length())).append(",").append(String.valueOf(coordinates.get(coordinates.size() - 2)), 0, Math.min(8, String.valueOf(coordinates.get(coordinates.size() - 2)).length())).append("]"); + statement.append("[").append(String.valueOf(coordinates.get(coordinates.size() - 1)).substring(0, Math.min(8, String.valueOf(coordinates.get(coordinates.size() - 1)).length()))).append(",").append(String.valueOf(coordinates.get(coordinates.size() - 2)).substring(0, Math.min(8, String.valueOf(coordinates.get(coordinates.size() - 2)).length()))).append("]"); statement.append("]]}},"); statement.append(System.lineSeparator()); @@ -782,7 +793,7 @@ private PointList expandAndBufferPointList(PointList list, double bufferSize, do double dy2 = dx * scale; extendedList.add(lat0 + dy2, lon0 + dx2); extendedList.add(lat0 - dy2, lon0 - dx2); - if (i == list.size() - 2) { + if(i == list.size() - 2) { extendedList.add(lat1 + dy2, lon1 + dx2); extendedList.add(lat1 - dy2, lon1 - dx2); }