Ejemplo n.º 1
0
 def test_bbox_for_tile(self):
     from raw_tiles.util import bbox_for_tile, MERCATOR_WORLD_SIZE
     c = 0.5 * MERCATOR_WORLD_SIZE
     self.assertEquals((-c, -c, c, c), bbox_for_tile(0, 0, 0))
     self.assertEquals((-c, 0, 0, c), bbox_for_tile(1, 0, 0))
     self.assertEquals((-c, -c, 0, 0), bbox_for_tile(1, 0, 1))
     self.assertEquals((0, 0, c, c), bbox_for_tile(1, 1, 0))
     self.assertEquals((0, -c, c, 0), bbox_for_tile(1, 1, 1))
Ejemplo n.º 2
0
    def __call__(self, table_reader, tile):
        source_locations = []
        timing = {}

        with time_block(timing, self.table_name):

            if self.bbox_expansion_factor:
                bounds = bbox_for_tile(tile.z, tile.x, tile.y)
                padded_bounds = calculate_padded_bounds(
                    self.bbox_expansion_factor, bounds)
                box2d = st_box2d_for_bbox(padded_bounds)

            else:
                box2d = tile.box2d()

            template_name = self.table_name + ".sql"

            try:
                table = table_reader.read_table(template_name,
                                                self.table_name,
                                                st_box2d=box2d)
            except Exception as e:
                raise type(e), \
                    '%s in table %r' % (str(e), self.table_name), \
                    exc_info()[2]

        source_locations.append(table)

        return source_locations, timing
Ejemplo n.º 3
0
    def test_corner_overlap(self):
        # a box around the corner of a tile should return the four
        # neighbours of that tile.
        from tilequeue.query.rawr import _tiles
        from raw_tiles.tile import Tile
        from raw_tiles.util import bbox_for_tile

        tile = Tile(15, 5241, 12665)

        zoom = tile.z
        tile_bbox = bbox_for_tile(tile.z, tile.x, tile.y)

        # extract the top left corner
        x = tile_bbox[0]
        y = tile_bbox[3]
        # make a small bounding box around that
        w = 10
        unpadded_bounds = (x - w, y - w, x + w, y + w)
        tiles = set(_tiles(zoom, unpadded_bounds))

        expected = set()
        for dx in (0, -1):
            for dy in (0, -1):
                expected.add(Tile(tile.z, tile.x + dx, tile.y + dy))

        self.assertEquals(expected, tiles)
Ejemplo n.º 4
0
    def test_single_tile(self):
        from tilequeue.query.rawr import _tiles
        from raw_tiles.tile import Tile
        from raw_tiles.util import bbox_for_tile

        tile = Tile(15, 5241, 12665)

        zoom = tile.z
        unpadded_bounds = bbox_for_tile(tile.z, tile.x, tile.y)
        tiles = _tiles(zoom, unpadded_bounds)

        self.assertEquals([tile], list(tiles))
Ejemplo n.º 5
0
    def test_multiple_tiles(self):
        from tilequeue.query.rawr import _tiles
        from raw_tiles.tile import Tile
        from raw_tiles.util import bbox_for_tile

        tile = Tile(15, 5241, 12665)

        # query at one zoom higher - should get 4 child tiles.
        zoom = tile.z + 1
        unpadded_bounds = bbox_for_tile(tile.z, tile.x, tile.y)
        tiles = list(_tiles(zoom, unpadded_bounds))

        self.assertEquals(4, len(tiles))
        for child in tiles:
            self.assertEquals(tile, child.parent())
Ejemplo n.º 6
0
    def __call__(self, table_reader, tile):
        source_locations = []
        timing = {}

        with time_block(timing, self.table_name):

            if self.bbox_expansion_factor:
                bounds = bbox_for_tile(tile.z, tile.x, tile.y)
                padded_bounds = calculate_padded_bounds(
                    self.bbox_expansion_factor, bounds)
                box2d = st_box2d_for_bbox(padded_bounds)

            else:
                box2d = tile.box2d()

            template_name = self.table_name + ".sql"
            table = table_reader.read_table(template_name,
                                            self.table_name,
                                            st_box2d=box2d)
        source_locations.append(table)

        return source_locations, timing
Ejemplo n.º 7
0
 def as_shapely(self):
     return make_box(*bbox_for_tile(self.z, self.x, self.y))