public static Station findClosestStation(StationTimeSeriesFeatureCollection stationFeatCol, LatLonPoint pt)
          throws IOException {
    double lat = pt.getLatitude();
    double lon = pt.getLongitude();
    double cos = Math.cos(Math.toRadians(lat));
    List<StationFeature> stations = stationFeatCol.getStationFeatures();
    Station min_station = stations.get(0);
    double min_dist = Double.MAX_VALUE;

    for (Station s : stations) {
      double lat1 = s.getLatitude();
      double lon1 = LatLonPointImpl.lonNormal(s.getLongitude(), lon);
      double dy = Math.toRadians(lat - lat1);
      double dx = cos * Math.toRadians(lon - lon1);
      double dist = dy * dy + dx * dx;
      if (dist < min_dist) {
        min_dist = dist;
        min_station = s;
      }
    }
    return min_station;
  }
public static Station findClosestStation ( StationTimeSeriesFeatureCollection stationFeatCol , LatLonPoint pt ) throws IOException { double lat = pt . getLatitude ( ) ; double lon = pt . getLongitude ( ) ; double cos = Math . cos ( Math . toRadians ( lat ) ) ; List < StationFeature > stations = stationFeatCol . getStationFeatures ( ) ; Station min_station = stations . get ( 0 ) ; double min_dist = Double . MAX_VALUE ; for ( Station s : stations ) { double lat1 = s . getLatitude ( ) ; double lon1 = LatLonPointImpl . lonNormal ( s . getLongitude ( ) , lon ) ; double dy = Math . toRadians ( lat - lat1 ) ; double dx = cos * Math . toRadians ( lon - lon1 ) ; double dist = dy * dy + dx * dx ; if ( dist < min_dist ) { min_dist = dist ; min_station = s ; } } return min_station ; }
/*
Find the station closest to the specified point.
The metric is (lat-lat0)**2 + (cos(lat0)*(lon-lon0))**2

@param lat latitude value
@param lon longitude value
@return name of station closest to the specified point
@throws IOException if read error