Exemple #1
0
def people_close_to(coordinates: Union[tuple, Coordinates],
                    people: Iterable[Person], distance: float):
    """
    Filters `people` and returns a generator with the :obj:`Person` instances whose coordinates
    are closer than `distance` from `coordinates`

    Args:
        coordinates: coordinates from which it will measure the distance
        people: Iterable of :obj:`Person` to be filtered by the distance
        distance: maximum distance in kilometers

    Returns:
        Iterable of :obj:`Person`: objects whose coordinates are closer than `distance`
            to `coordinates`
    """
    return (
        p for p in people
        if geo.great_circle_distance(coordinates, p.coordinates) <= distance)
Exemple #2
0
    def test_equivalence_of_pos_and_neg_180_longitude(self):
        distance1 = great_circle_distance((0, -180), (0, 180))
        distance2 = great_circle_distance((0, 180), (0, -180))

        self.assertEqual(distance1, 0)
        self.assertEqual(distance2, 0)
Exemple #3
0
 def test_coordinates_instances(self):
     dist1 = great_circle_distance(Coordinates("1", "30"), Coordinates("20", "60"))
     dist2 = great_circle_distance((1, 30), (20, 60))
     self.assertEqual(dist1, dist2)
Exemple #4
0
 def test_half_trip_around_equator(self):
     expected_distance = EARTH_CIRCUMFERENCE / 2
     self.assertEqual(great_circle_distance((0, 0), (0, 180)), expected_distance)
Exemple #5
0
 def test_distance_between_poles(self):
     expected_distance = EARTH_CIRCUMFERENCE / 2
     self.assertEqual(great_circle_distance(NORTH_POLE, SOUTH_POLE), expected_distance)
Exemple #6
0
 def test_no_distance_is_greater_than_half_equator(self, lat_a, lng_a, lat_b, lng_b):
     """Any two coordinates will have a distance less than or equals to half the equator"""
     max_distance = EARTH_CIRCUMFERENCE / 2 + 1  # To avoid precision errors
     self.assertLessEqual(great_circle_distance((lat_a, lng_a), (lat_b, lng_b)), max_distance)
Exemple #7
0
 def test_any_distance_greater_than_or_equals_to_zero(self, lat_a, lng_a, lat_b, lng_b):
     """Any two coordinates will have a distance greater than or equals to zero"""
     self.assertGreaterEqual(great_circle_distance((lat_a, lng_a), (lat_b, lng_b)), 0)
Exemple #8
0
 def test_zero_distance(self, lat, lng):
     """Same coordinates will have a distance almost equals to zero"""
     self.assertAlmostEqual(great_circle_distance((lat, lng), (lat, lng)), 0, 3)