Beispiel #1
0
    def nearest_stations(self, latitude, longitude, all=False, limit=10):
        """
        Select most current stations datasets.

        Stolen from https://github.com/marians/dwd-weather
        """

        # Retrieve stations
        stations = self.get_stations(all=all)

        # Build list of distances to corresponding station
        distances = []
        for index, station in stations.iterrows():
            distance = haversine_distance(
                (longitude, latitude),
                (station['geograph.Laenge'], station['geograph.Breite']))
            distances.append(distance)

        # Insert list of distances as new column
        stations.insert(1, 'Distanz', distances)

        # Sort ascending by distance value and limit row count
        stations = stations.sort_values('Distanz').head(n=limit)

        # Convert Series to DataFrame again
        frame = pd.DataFrame(stations)

        return frame
Beispiel #2
0
    def nearest_station(self, latitude, longitude, all=False):
        """
        Select most current stations datasets.

        Stolen from https://github.com/marians/dwd-weather
        """
        closest = None
        closest_distance = 99999999999
        for index, station in self.get_stations(all=all).iterrows():
            d = haversine_distance(
                (longitude, latitude),
                (station["geograph.Laenge"], station["geograph.Breite"]))
            if d < closest_distance:
                closest = station
                closest_distance = d
        return closest.to_frame()