All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.routing.graphfinder.DirectGraphFinder Maven / Gradle / Ivy

package org.opentripplanner.routing.graphfinder;

import com.beust.jcommander.internal.Lists;
import java.util.List;
import org.locationtech.jts.geom.Coordinate;
import org.opentripplanner.common.geometry.SphericalDistanceLibrary;
import org.opentripplanner.model.FeedScopedId;
import org.opentripplanner.model.TransitMode;
import org.opentripplanner.routing.RoutingService;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.impl.StreetVertexIndex;
import org.opentripplanner.routing.vertextype.TransitStopVertex;

/**
 * A Graph finder used in conjunction with a graph, which does not have a street network included.
 * Also usable if performance is more important or if the "as the crow flies" distance id required.
 */
public class DirectGraphFinder implements GraphFinder {

  private final StreetVertexIndex streetIndex;

  public DirectGraphFinder(Graph graph) {
    this.streetIndex = graph.getStreetIndex();
  }

  /**
   * Return all stops within a certain radius of the given vertex, using straight-line distance independent of streets.
   * If the origin vertex is a StopVertex, the result will include it.
   */
  @Override
  public List findClosestStops(double lat, double lon, double radiusMeters) {
    List stopsFound = Lists.newArrayList();
    Coordinate coordinate = new Coordinate(lon, lat);
    for (TransitStopVertex it : streetIndex.getNearbyTransitStops(coordinate, radiusMeters)) {
      double distance = Math.round(SphericalDistanceLibrary.distance(coordinate, it.getCoordinate()));
      if (distance < radiusMeters) {
        NearbyStop sd = new NearbyStop(
            it,
            distance,
            null,
            null
        );
        stopsFound.add(sd);
      }
    }

    stopsFound.sort(NearbyStop::compareTo);

    return stopsFound;
  }

  @Override
  public List findClosestPlaces(
      double lat, double lon, double maxDistance, int maxResults, List filterByModes,
      List filterByPlaceTypes, List filterByStops,
      List filterByRoutes, List filterByBikeRentalStations,
      List filterByBikeParks, List filterByCarParks, RoutingService routingService
  ) {
    throw new UnsupportedOperationException("Not implemented");
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy