Search in sources :

Example 1 with StopLinkedTooFar

use of org.opentripplanner.graph_builder.issues.StopLinkedTooFar in project OpenTripPlanner by opentripplanner.

the class SimpleStreetSplitter method linkToStreetEdges.

public boolean linkToStreetEdges(Vertex vertex, TraverseMode traverseMode, RoutingRequest options, int radiusMeters) {
    final double radiusDeg = SphericalDistanceLibrary.metersToDegrees(radiusMeters);
    Envelope env = new Envelope(vertex.getCoordinate());
    // Perform a simple local equirectangular projection, so distances are expressed in degrees latitude.
    final double xscale = Math.cos(vertex.getLat() * Math.PI / 180);
    // Expand more in the longitude direction than the latitude direction to account for converging meridians.
    env.expandBy(radiusDeg / xscale, radiusDeg);
    final double DUPLICATE_WAY_EPSILON_DEGREES = SphericalDistanceLibrary.metersToDegrees(DUPLICATE_WAY_EPSILON_METERS);
    final TraverseModeSet traverseModeSet = new TraverseModeSet(traverseMode);
    if (traverseMode == TraverseMode.BICYCLE) {
        traverseModeSet.setWalk(true);
    }
    // Scope block to avoid confusing edge-related local variables with stop-related variables below.
    {
        // Perform several transformations at once on the edges returned by the index.
        // Only consider street edges traversable by the given mode and still present in the graph.
        // Calculate a distance to each of those edges, and keep only the ones within the search radius.
        List<DistanceTo<StreetEdge>> candidateEdges = idx.query(env).stream().filter(StreetEdge.class::isInstance).map(StreetEdge.class::cast).filter(e -> e.canTraverse(traverseModeSet) && edgeReachableFromGraph(e)).map(e -> new DistanceTo<>(e, distance(vertex, e, xscale))).filter(ead -> ead.distanceDegreesLat < radiusDeg).collect(Collectors.toList());
        // being non-deterministic.
        if (!candidateEdges.isEmpty()) {
            // There is at least one appropriate edge within range.
            double closestDistance = candidateEdges.stream().mapToDouble(ce -> ce.distanceDegreesLat).min().getAsDouble();
            candidateEdges.stream().filter(ce -> ce.distanceDegreesLat <= closestDistance + DUPLICATE_WAY_EPSILON_DEGREES).forEach(ce -> link(vertex, ce.item, xscale, options));
            // Warn if a linkage was made for a transit stop, but the linkage was suspiciously long.
            if (vertex instanceof TransitStopVertex) {
                int distanceMeters = (int) SphericalDistanceLibrary.degreesLatitudeToMeters(closestDistance);
                if (distanceMeters > WARNING_DISTANCE_METERS) {
                    issueStore.add(new StopLinkedTooFar((TransitStopVertex) vertex, distanceMeters));
                }
            }
            return true;
        }
    }
    if (radiusMeters >= MAX_SEARCH_RADIUS_METERS) {
        // We only link to stops if we are searching for origin/destination and for that we need transitStopIndex.
        if (destructiveSplitting || transitStopIndex == null) {
            return false;
        }
        LOG.debug("No street edge was found for {}, checking transit stop vertices.", vertex);
        List<TransitStopVertex> transitStopVertices = transitStopIndex.query(env);
        List<DistanceTo<TransitStopVertex>> candidateStops = transitStopVertices.stream().map(tsv -> new DistanceTo<>(tsv, distance(vertex, tsv, xscale))).filter(dts -> dts.distanceDegreesLat <= radiusDeg).collect(Collectors.toList());
        if (candidateStops.isEmpty()) {
            LOG.debug("No stops nearby.");
            return false;
        }
        // There is at least one stop within range.
        double closestDistance = candidateStops.stream().mapToDouble(c -> c.distanceDegreesLat).min().getAsDouble();
        candidateStops.stream().filter(dts -> dts.distanceDegreesLat <= closestDistance + DUPLICATE_WAY_EPSILON_DEGREES).map(dts -> dts.item).forEach(sv -> {
            LOG.debug("Linking vertex to stop: {}", sv.getName());
            makeTemporaryEdges((TemporaryStreetLocation) vertex, sv);
        });
        return true;
    }
    return false;
}
Also used : TemporaryFreeEdge(org.opentripplanner.routing.edgetype.TemporaryFreeEdge) DefaultStreetEdgeFactory(org.opentripplanner.graph_builder.services.DefaultStreetEdgeFactory) LinearLocation(org.locationtech.jts.linearref.LinearLocation) StopLinkedTooFar(org.opentripplanner.graph_builder.issues.StopLinkedTooFar) TemporaryVertex(org.opentripplanner.routing.vertextype.TemporaryVertex) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) LoggerFactory(org.slf4j.LoggerFactory) Coordinate(org.locationtech.jts.geom.Coordinate) SphericalDistanceLibrary(org.opentripplanner.common.geometry.SphericalDistanceLibrary) TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) EntranceUnlinked(org.opentripplanner.graph_builder.issues.EntranceUnlinked) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) SplitterVertex(org.opentripplanner.routing.vertextype.SplitterVertex) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Graph(org.opentripplanner.routing.graph.Graph) BikeRentalStationVertex(org.opentripplanner.routing.vertextype.BikeRentalStationVertex) TraverseMode(org.opentripplanner.routing.core.TraverseMode) GenericLocation(org.opentripplanner.model.GenericLocation) I18NString(org.opentripplanner.util.I18NString) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) TransitEntranceVertex(org.opentripplanner.routing.vertextype.TransitEntranceVertex) List(java.util.List) AreaEdge(org.opentripplanner.routing.edgetype.AreaEdge) P2(org.opentripplanner.common.model.P2) Iterables(com.google.common.collect.Iterables) TemporarySplitterVertex(org.opentripplanner.routing.vertextype.TemporarySplitterVertex) OSMWithTags(org.opentripplanner.openstreetmap.model.OSMWithTags) StopUnlinked(org.opentripplanner.graph_builder.issues.StopUnlinked) StreetEdgeFactory(org.opentripplanner.graph_builder.services.StreetEdgeFactory) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) TransitEntranceLink(org.opentripplanner.routing.edgetype.TransitEntranceLink) Function(java.util.function.Function) LocationIndexedLine(org.locationtech.jts.linearref.LocationIndexedLine) LocalizedString(org.opentripplanner.util.LocalizedString) ArrayList(java.util.ArrayList) DataImportIssue(org.opentripplanner.graph_builder.DataImportIssue) DataImportIssueStore(org.opentripplanner.graph_builder.DataImportIssueStore) HashGridSpatialIndex(org.opentripplanner.common.geometry.HashGridSpatialIndex) BikeParkUnlinked(org.opentripplanner.graph_builder.issues.BikeParkUnlinked) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Logger(org.slf4j.Logger) Vertex(org.opentripplanner.routing.graph.Vertex) StreetBikeRentalLink(org.opentripplanner.routing.edgetype.StreetBikeRentalLink) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) StreetBikeParkLink(org.opentripplanner.routing.edgetype.StreetBikeParkLink) GeometryUtils(org.opentripplanner.common.geometry.GeometryUtils) LineString(org.locationtech.jts.geom.LineString) StreetVertexIndex(org.opentripplanner.routing.impl.StreetVertexIndex) SpatialIndex(org.locationtech.jts.index.SpatialIndex) AreaEdgeList(org.opentripplanner.routing.edgetype.AreaEdgeList) BikeParkVertex(org.opentripplanner.routing.vertextype.BikeParkVertex) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) StreetTraversalPermission(org.opentripplanner.routing.edgetype.StreetTraversalPermission) ProgressTracker(org.opentripplanner.util.ProgressTracker) Envelope(org.locationtech.jts.geom.Envelope) Edge(org.opentripplanner.routing.graph.Edge) BikeRentalStationUnlinked(org.opentripplanner.graph_builder.issues.BikeRentalStationUnlinked) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) List(java.util.List) ArrayList(java.util.ArrayList) AreaEdgeList(org.opentripplanner.routing.edgetype.AreaEdgeList) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) StopLinkedTooFar(org.opentripplanner.graph_builder.issues.StopLinkedTooFar) Envelope(org.locationtech.jts.geom.Envelope)

Aggregations

Iterables (com.google.common.collect.Iterables)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 Envelope (org.locationtech.jts.geom.Envelope)1 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)1 LineString (org.locationtech.jts.geom.LineString)1 SpatialIndex (org.locationtech.jts.index.SpatialIndex)1 LinearLocation (org.locationtech.jts.linearref.LinearLocation)1 LocationIndexedLine (org.locationtech.jts.linearref.LocationIndexedLine)1 GeometryUtils (org.opentripplanner.common.geometry.GeometryUtils)1 HashGridSpatialIndex (org.opentripplanner.common.geometry.HashGridSpatialIndex)1 SphericalDistanceLibrary (org.opentripplanner.common.geometry.SphericalDistanceLibrary)1 P2 (org.opentripplanner.common.model.P2)1 DataImportIssue (org.opentripplanner.graph_builder.DataImportIssue)1 DataImportIssueStore (org.opentripplanner.graph_builder.DataImportIssueStore)1 BikeParkUnlinked (org.opentripplanner.graph_builder.issues.BikeParkUnlinked)1