コード例 #1
0
  private static LatLngBounds getSearchBoundsAsLatLngBounds(double radius) {

    CoordinateBounds bounds = getSearchBounds(radius);

    LatLngBounds b = LatLngBounds.newInstance();
    b.extend(LatLng.newInstance(bounds.getMinLat(), bounds.getMinLon()));
    b.extend(LatLng.newInstance(bounds.getMaxLat(), bounds.getMaxLon()));
    return b;
  }
  @SuppressWarnings("unchecked")
  public Map<NBStop, List<Stop>> getPotentialStopMatches(
      List<NBRoute> nbRoutes, Collection<Stop> gtfsStops) {

    Map<String, NBStop> nbStopsByTag = getStopsByTag(nbRoutes);

    STRtree tree = new STRtree(gtfsStops.size());
    for (Stop stop : gtfsStops) {
      tree.insert(new Envelope(new Coordinate(stop.getLon(), stop.getLat())), stop);
    }
    tree.build();

    Map<NBStop, List<Stop>> potentialMatches = new HashMap<NBStop, List<Stop>>();
    int stopsWithNoMatches = 0;
    for (NBStop nbStop : nbStopsByTag.values()) {
      CoordinateBounds b =
          SphericalGeometryLibrary.bounds(
              nbStop.getLat(), nbStop.getLon(), _stopMatchingDistanceThreshold);
      Envelope env = new Envelope(b.getMinLon(), b.getMaxLon(), b.getMinLat(), b.getMaxLat());
      List<Stop> stopsInEnvelope = tree.query(env);
      if (stopsInEnvelope.isEmpty()) {
        _log.warn(
            "stop with no match: tag="
                + nbStop.getTag()
                + " lat="
                + nbStop.getLat()
                + " lon="
                + nbStop.getLon());
        stopsWithNoMatches++;
      }
      potentialMatches.put(nbStop, stopsInEnvelope);
    }

    if (stopsWithNoMatches > 0) {
      _log.warn("stops without matches: " + stopsWithNoMatches + "/" + nbStopsByTag.size());
    }

    return potentialMatches;
  }