33
33
import com .graphhopper .storage .GraphHopperStorage ;
34
34
import com .graphhopper .storage .index .QueryResult ;
35
35
import com .graphhopper .util .*;
36
+ import com .graphhopper .util .exceptions .ConnectionNotFoundException ;
36
37
import com .graphhopper .util .exceptions .PointNotFoundException ;
37
38
import com .graphhopper .util .shapes .GHPoint ;
38
39
import com .vividsolutions .jts .geom .Coordinate ;
39
40
import com .vividsolutions .jts .geom .GeometryFactory ;
40
41
import com .vividsolutions .jts .geom .LineString ;
41
42
import org .heigit .ors .mapmatching .RouteSegmentInfo ;
43
+ import org .heigit .ors .routing .RouteSearchParameters ;
42
44
import org .heigit .ors .routing .RoutingProfileCategory ;
43
45
import org .heigit .ors .routing .graphhopper .extensions .core .CoreAlgoFactoryDecorator ;
44
46
import org .heigit .ors .routing .graphhopper .extensions .core .CoreLMAlgoFactoryDecorator ;
45
47
import org .heigit .ors .routing .graphhopper .extensions .core .PrepareCore ;
48
+ import org .heigit .ors .routing .graphhopper .extensions .edgefilters .AvoidBordersEdgeFilter ;
46
49
import org .heigit .ors .routing .graphhopper .extensions .edgefilters .EdgeFilterSequence ;
47
50
import org .heigit .ors .routing .graphhopper .extensions .edgefilters .core .AvoidBordersCoreEdgeFilter ;
48
51
import org .heigit .ors .routing .graphhopper .extensions .edgefilters .core .AvoidFeaturesCoreEdgeFilter ;
49
52
import org .heigit .ors .routing .graphhopper .extensions .edgefilters .core .HeavyVehicleCoreEdgeFilter ;
50
53
import org .heigit .ors .routing .graphhopper .extensions .edgefilters .core .WheelchairCoreEdgeFilter ;
51
54
import org .heigit .ors .routing .graphhopper .extensions .edgefilters .core .MaximumSpeedCoreEdgeFilter ;
55
+ import org .heigit .ors .routing .graphhopper .extensions .reader .borders .CountryBordersReader ;
56
+ import org .heigit .ors .routing .graphhopper .extensions .storages .BordersGraphStorage ;
57
+ import org .heigit .ors .routing .graphhopper .extensions .storages .GraphStorageUtils ;
58
+ import org .heigit .ors .routing .graphhopper .extensions .storages .builders .GraphStorageBuilder ;
59
+ import org .heigit .ors .routing .graphhopper .extensions .util .ORSPMap ;
52
60
import org .heigit .ors .routing .graphhopper .extensions .weighting .MaximumSpeedWeighting ;
53
61
import org .heigit .ors .routing .graphhopper .extensions .util .ORSParameters ;
62
+ import org .heigit .ors .routing .pathprocessors .BordersExtractor ;
54
63
import org .heigit .ors .util .CoordTools ;
55
64
import org .slf4j .Logger ;
56
65
import org .slf4j .LoggerFactory ;
@@ -256,6 +265,7 @@ else if (ALT_ROUTE.equalsIgnoreCase(algoStr))
256
265
StopWatch sw = new StopWatch ().start ();
257
266
List <QueryResult > qResults = routingTemplate .lookup (points , encoder );
258
267
double [] radiuses = request .getMaxSearchDistances ();
268
+ checkAvoidBorders (processContext , request , qResults );
259
269
if (points .size () == qResults .size ()) {
260
270
for (int placeIndex = 0 ; placeIndex < points .size (); placeIndex ++) {
261
271
QueryResult qr = qResults .get (placeIndex );
@@ -264,7 +274,6 @@ else if (ALT_ROUTE.equalsIgnoreCase(algoStr))
264
274
}
265
275
}
266
276
}
267
-
268
277
ghRsp .addDebugInfo ("idLookup:" + sw .stop ().getSeconds () + "s" );
269
278
if (ghRsp .hasErrors ())
270
279
return Collections .emptyList ();
@@ -435,6 +444,61 @@ public RouteSegmentInfo getRouteSegment(double[] latitudes, double[] longitudes,
435
444
return result ;
436
445
}
437
446
447
+ /**
448
+ * Check whether the route processing has to start. If avoid all borders is set and the routing points are in different countries,
449
+ * there is no need to even start routing.
450
+ * @param processContext Used to get the bordersReader to check isOpen for avoid Controlled. Currently not used
451
+ * @param request To get the avoid borders setting
452
+ * @param queryResult To get the edges of the queries and check which country they're in
453
+ */
454
+ private void checkAvoidBorders (GraphProcessContext processContext , GHRequest request , List <QueryResult > queryResult ) {
455
+ /* Avoid borders */
456
+ ORSPMap params = (ORSPMap )request .getAdditionalHints ();
457
+ boolean isRouteable = true ;
458
+
459
+ if (params .hasObj ("avoid_borders" )) {
460
+ RouteSearchParameters routeSearchParameters = (RouteSearchParameters ) params .getObj ("avoid_borders" );
461
+ //Avoiding All borders
462
+ if (routeSearchParameters .hasAvoidBorders () && routeSearchParameters .getAvoidBorders () == BordersExtractor .Avoid .ALL ) {
463
+ List <Integer > edgeIds = new ArrayList <>();
464
+ for (int placeIndex = 0 ; placeIndex < queryResult .size (); placeIndex ++) {
465
+ edgeIds .add (queryResult .get (placeIndex ).getClosestEdge ().getEdge ());
466
+ }
467
+ BordersExtractor bordersExtractor = new BordersExtractor (GraphStorageUtils .getGraphExtension (getGraphHopperStorage (), BordersGraphStorage .class ), null );
468
+ isRouteable = bordersExtractor .isSameCountry (edgeIds );
469
+ }
470
+ //TODO Avoiding CONTROLLED borders
471
+ //Currently this is extremely messy, as for some reason the READER stores data in addition to the BordersStorage.
472
+ //At the same time, it is not possible to get isOpen from the Reader via ids, because it only takes Strings. But there are no Strings in the Storage.
473
+ //So no controlled borders for now until this whole thing is refactored and the Reader is an actual reader and not a storage.
474
+
475
+ // if(routeSearchParameters.hasAvoidBorders() && routeSearchParameters.getAvoidBorders() == BordersExtractor.Avoid.CONTROLLED) {
476
+ // GraphStorageBuilder countryBordersReader;
477
+ // if(processContext.getStorageBuilders().size() > 0) {
478
+ // countryBordersReader = processContext.getStorageBuilders().get(0);
479
+ // int i = 1;
480
+ // while (i < processContext.getStorageBuilders().size() && !(countryBordersReader instanceof CountryBordersReader)) {
481
+ // countryBordersReader = processContext.getStorageBuilders().get(i);
482
+ // i++;
483
+ // }
484
+ //
485
+ // List<Integer> edgeIds = new ArrayList<>();
486
+ // for (int placeIndex = 0; placeIndex < queryResult.size(); placeIndex++) {
487
+ // edgeIds.add(queryResult.get(placeIndex).getClosestEdge().getEdge());
488
+ // }
489
+ // BordersExtractor bordersExtractor = new BordersExtractor(GraphStorageUtils.getGraphExtension(getGraphHopperStorage(), BordersGraphStorage.class), null);
490
+ // if (!bordersExtractor.isSameCountry(edgeIds)) {
491
+ // isRouteable == ((CountryBordersReader) countryBordersReader).isOpen(id0, id1)
492
+ // ...
493
+ // }
494
+ // }
495
+ // }
496
+ }
497
+ if (!isRouteable )
498
+ throw new ConnectionNotFoundException ("Route not found due to avoiding borders" , Collections .<String , Object >emptyMap ());
499
+
500
+ }
501
+
438
502
public GHResponse constructFreeHandRoute (GHRequest request ) {
439
503
LineString directRouteGeometry = constructFreeHandRouteGeometry (request );
440
504
PathWrapper directRoutePathWrapper = constructFreeHandRoutePathWrapper (directRouteGeometry );
0 commit comments