Пример #1
0
 def test_bounds(self):
     # bounds
     bbox.validate_bbox((-180, -90, 180, 90))
     bbox.validate_bbox((180, -90, 180, 90))
     self.assertRaises(AssertionError, bbox.validate_bbox,
                       (-180.1, -90, 180, 90))
     self.assertRaises(AssertionError, bbox.validate_bbox,
                       (-180, -90.1, 180, 90))
     self.assertRaises(AssertionError, bbox.validate_bbox,
                       (-180, -90, 180.1, 90))
     self.assertRaises(AssertionError, bbox.validate_bbox,
                       (-180, -90, 180, 90.1))
     # left < right, bottom < top
     self.assertRaises(AssertionError, bbox.validate_bbox, (180, 0, 0, 0))
     self.assertRaises(AssertionError, bbox.validate_bbox, (0, 0, -180, 0))
     self.assertRaises(AssertionError, bbox.validate_bbox, (0, 90, 0, 0))
     self.assertRaises(AssertionError, bbox.validate_bbox, (0, 0, 0, -90))
 def get_bbox_tiles(self, bbox):
     left, bottom, right, top = validate_bbox(bbox)
     min_x = int(math.floor(left))
     max_x = int(math.ceil(right))
     min_y = int(math.floor(bottom))
     max_y = int(math.ceil(top))
     expect = (max_x - min_x + 1) * (max_y - min_y + 1)
     tiles = set()
     for x in range(min_x, max_x):
         for y in range(min_y, max_y):
             tiles.add((0, x, y))
     return tiles
 def get_bbox_tiles(self, bbox):
     left, bottom, right, top = validate_bbox(bbox)
     ybound = 85.0511
     if bottom <= -ybound:
         bottom = -ybound
     if top > ybound:
         top = ybound
     if right >= 180:
         right = 179.999
     size = 2**self.zoom
     xt = lambda x: int((x + 180.0) / 360.0 * size)
     yt = lambda y: int((1.0 - math.log(
         math.tan(math.radians(y)) +
         (1 / math.cos(math.radians(y)))) / math.pi) / 2.0 * size)
     tiles = []
     for x in range(xt(left), xt(right) + 1):
         for y in range(yt(top), yt(bottom) + 1):
             tiles.append([self.zoom, x, y])
     return tiles
Пример #4
0
 def test_returns_array(self):
     self.assertEquals(bbox.validate_bbox([1, 2, 3, 4]),
                       [1.0, 2.0, 3.0, 4.0])