Ejemplo n.º 1
0
    def bounding_box(self):
        """Get extreme latitude and longitude values.

        Return Rectangle that contains all points"""

        lats = sorted([p.latitude for p in self.points])
        lons = sorted([p.longitude for p in self.points])
        return Rectangle(Point(min(lats), min(lons)),
                         Point(max(lats), max(lons)))
Ejemplo n.º 2
0
    def __init__(self, point_a, point_b):
        """Create rectangle defined by opposite corners

        Parameters point_a and point_b are Point instances."""

        assert point_a != point_b, "Corner points cannot be the same"
        self.corners = [point_a, point_b]
        self.points = [
            point_a,
            Point(point_a.latitude, point_b.longitude), point_b,
            Point(point_b.latitude, point_a.longitude)
        ]
Ejemplo n.º 3
0
 def test_inside_area(self):
     inside_points = [
         Point(*i)
         for i in [(10., 20.), (30., -5.), (18., 15.), (29., -1), (10., -3)]
     ]
     outside_points = [
         Point(*i)
         for i in [(-10., -170.), (-70., 0.), (0., 40), (20.,
                                                         -10.), (50., 0.)]
     ]
     for point_list, test_func in [(inside_points, 'assertTrue'),
                                   (outside_points, 'assertFalse')]:
         for p in point_list:
             with self.subTest("Area -> point: {}".format(p)):
                 getattr(self, test_func)(self.rect.inside_area(p))
             with self.subTest("Point -> area: {}".format(p)):
                 getattr(self, test_func)(p.inside_area(self.rect))
Ejemplo n.º 4
0
    def geocode(self, query):
        """Tries to fetch coordinates for given query."""

        assert type(query) is str

        url = self._urls["geocode"] + "?q=" + query
        try:
            res = self._browser.get(url).json()
        except requests.exceptions.ConnectionError as e:
            raise Error("Cannot load geocode page.") from e

        if res["status"] != "success":
            raise GeocodeError(res["msg"])

        return Point(float(res["data"]["lat"]), float(res["data"]["lng"]))
Ejemplo n.º 5
0
 def mean_point(self):
     """Return point with average latitude and longitude of points"""
     lats = [p.latitude for p in self.points]
     lons = [p.longitude for p in self.points]
     return Point(sum(lats) / len(lats), sum(lons) / len(lons))
Ejemplo n.º 6
0
 def setUp(self):
     self.p = Polygon(*[
         Point(*i)
         for i in [(10., 20.), (30., -5.), (-10., -170.), (-70.,
                                                           0.), (0., 40)]
     ])
Ejemplo n.º 7
0
 def setUp(self):
     self.rect = Rectangle(Point(10., 20.), Point(30., -5.))