Beispiel #1
0
    def parse_altitude(cls, distance, unit):
        """
        Parse altitude managing units conversion::

            >>> Point.parse_altitude(712, 'm')
            0.712
            >>> Point.parse_altitude(712, 'km')
            712.0
            >>> Point.parse_altitude(712, 'mi')
            1145.852928

        :param float distance: Numeric value of altitude.
        :param str unit: ``distance`` unit. Supported units
            are listed in :meth:`.from_string` doc.
        """
        if distance is not None:
            distance = float(distance)
            CONVERTERS = {
                'km': lambda d: d,
                'm': lambda d: units.kilometers(meters=d),
                'mi': lambda d: units.kilometers(miles=d),
                'ft': lambda d: units.kilometers(feet=d),
                'nm': lambda d: units.kilometers(nautical=d),
                'nmi': lambda d: units.kilometers(nautical=d)
            }
            try:
                return CONVERTERS[unit](distance)
            except KeyError:
                raise NotImplementedError(
                    'Bad distance unit specified, valid are: %r' %
                    CONVERTERS.keys())
        else:
            return distance
Beispiel #2
0
 def parse_altitude(cls, distance, unit):
     if distance is not None:
         distance = float(distance)
         CONVERTERS = {
             'km': lambda d: d,
             'm': lambda d: units.kilometers(meters=d),
             'mi': lambda d: units.kilometers(miles=d),
             'ft': lambda d: units.kilometers(feet=d),
             'nm': lambda d: units.kilometers(nautical=d),
             'nmi': lambda d: units.kilometers(nautical=d)
         }
         return CONVERTERS[unit](distance)
     else:
         return distance
Beispiel #3
0
 def parse_altitude(cls, distance, unit):
     if distance is not None:
         distance = float(distance)
         CONVERTERS = {
             'km': lambda d: d,
             'm': lambda d: units.kilometers(meters=d),
             'mi': lambda d: units.kilometers(miles=d),
             'ft': lambda d: units.kilometers(feet=d),
             'nm': lambda d: units.kilometers(nautical=d),
             'nmi': lambda d: units.kilometers(nautical=d)
         }
         return CONVERTERS[unit](distance)
     else:
         return distance
Beispiel #4
0
 def parse_altitude(cls, distance, unit):
     if distance is not None:
         distance = float(distance)
         CONVERTERS = {
             'km': lambda d: d,
             'm': lambda d: units.kilometers(meters=d),
             'mi': lambda d: units.kilometers(miles=d),
             'ft': lambda d: units.kilometers(feet=d),
             'nm': lambda d: units.kilometers(nautical=d),
             'nmi': lambda d: units.kilometers(nautical=d)
         }
         try:
             return CONVERTERS[unit](distance)
         except KeyError:  # pragma: no cover
             raise NotImplementedError(
                 'Bad distance unit specified, valid are: %r' %
                 CONVERTERS.keys())
     else:
         return distance
Beispiel #5
0
 def parse_altitude(cls, distance, unit):
     if distance is not None:
         distance = float(distance)
         CONVERTERS = {
             'km': lambda d: d,
             'm': lambda d: units.kilometers(meters=d),
             'mi': lambda d: units.kilometers(miles=d),
             'ft': lambda d: units.kilometers(feet=d),
             'nm': lambda d: units.kilometers(nautical=d),
             'nmi': lambda d: units.kilometers(nautical=d)
         }
         try:
             return CONVERTERS[unit](distance)
         except KeyError: # pragma: no cover
             raise NotImplementedError(
                 'Bad distance unit specified, valid are: %r' % CONVERTERS.keys()
             )
     else:
         return distance
Beispiel #6
0
    def __init__(self, *args, **kwargs):
        kilometers = kwargs.pop('kilometers', 0)
        if len(args) == 1:
            # if we only get one argument we assume
            # it's a known distance instead of
            # calculating it first
            kilometers += args[0]
        elif len(args) > 1:
            for a, b in util.pairwise(args):
                kilometers += self.measure(a, b)

        kilometers += units.kilometers(**kwargs)
        self.__kilometers = kilometers
Beispiel #7
0
    def __init__(self, *args, **kwargs):
        kilometers = kwargs.pop('kilometers', 0)
        if len(args) == 1:
            # if we only get one argument we assume
            # it's a known distance instead of
            # calculating it first
            kilometers += args[0]
        elif len(args) > 1:
            for a, b in util.pairwise(args):
                kilometers += self.measure(a, b)

        kilometers += units.kilometers(**kwargs)
        self.__kilometers = kilometers
Beispiel #8
0
    def __init__(self, *args, **kwargs):
        """
        There are 3 ways to create a distance:

        - From kilometers::

            >>> from geopy.distance import Distance
            >>> Distance(1.42)
            Distance(1.42)

        - From units::

            >>> from geopy.distance import Distance
            >>> Distance(kilometers=1.42)
            Distance(1.42)
            >>> Distance(miles=1)
            Distance(1.609344)

        - From points (for non-abstract distances only),
          calculated as a sum of distances between all points::

            >>> from geopy.distance import geodesic
            >>> geodesic((40, 160), (40.1, 160.1))
            Distance(14.003702498106215)
            >>> geodesic((40, 160), (40.1, 160.1), (40.2, 160.2))
            Distance(27.999954644813478)
        """

        kilometers = kwargs.pop('kilometers', 0)
        if len(args) == 1:
            # if we only get one argument we assume
            # it's a known distance instead of
            # calculating it first
            kilometers += args[0]
        elif len(args) > 1:
            for a, b in util.pairwise(args):
                kilometers += self.measure(a, b)

        kilometers += units.kilometers(**kwargs)
        self.__kilometers = kilometers
Beispiel #9
0
def calculate_surrounding_coords(sample, num_miles):
    """The project asks to address the question "How many [statistic] COVID-19 occurred
    within [num_miles] from [US County]?"

    My approach was to calculate the surrounding coordinates from the base coordinate within
    the user specified num_miles radius and zoom in on that area in Plotly.

    Args:
    =====
        sample (pd.DataFrame): The pandas DataFrame filtered by user-specified county
        num_miles (int)  : The number of miles between 0 and 1000

    Returns:
    =======
        lat (list): A list that contains the latitude values from NSEW
        lon (list): A list that contains the longitude values from NSEW
    """
    miles_to_km = kilometers(miles=num_miles)

    start = Point(sample["latitude"].values[0], sample["longitude"].values[0])

    d = geopy.distance.geodesic()

    dest_north = d.destination(start, distance=miles_to_km, bearing=0)
    dest_east = d.destination(start, distance=miles_to_km, bearing=90)
    dest_south = d.destination(start, distance=miles_to_km, bearing=180)
    dest_west = d.destination(start, distance=miles_to_km, bearing=270)

    lat = [
        dest_north.latitude, dest_east.latitude, dest_south.latitude,
        dest_west.latitude
    ]

    lon = [
        dest_north.longitude, dest_east.longitude, dest_south.longitude,
        dest_west.longitude
    ]

    return lat, lon