Esempio n. 1
0
 def test_one(self):
     tilestore = MBTilesTileStore(sqlite3.connect(':memory:'), content_type='image/png')
     self.assertEqual(len(tilestore), 0)
     tilestream = [Tile(TileCoord(1, 0, 0), data='data'), None, Tile(TileCoord(1, 0, 1), error=True)]
     tilestream = tilestore.put(tilestream)
     tiles = list(tilestream)
     self.assertEqual(len(tilestore), 2)
     self.assertEqual(len(tiles), 2)
     self.assertEqual(tiles[0].tilecoord, TileCoord(1, 0, 0))
     self.assertEqual(tiles[0].data, 'data')
     self.assertEqual(tiles[1].tilecoord, TileCoord(1, 0, 1))
     self.assertEqual(tiles[1].error, True)
     self.assertTrue(Tile(TileCoord(1, 0, 0)) in tilestore)
     self.assertTrue(Tile(TileCoord(1, 0, 1)) in tilestore)
     tilestream = [Tile(TileCoord(1, 0, 0)), Tile(TileCoord(1, 0, 1))]
     tilestream = tilestore.get(tilestream)
     consume(tilestream, None)
     self.assertEqual(tilestore.get_cheap_bounding_pyramid(), BoundingPyramid({1: (Bounds(0, 1), Bounds(0, 2))}))
     self.assertEqual(len(tilestore), 2)
     tiles = list(tilestore.list())
     self.assertEqual(len(tiles), 2)
     tiles = sorted(tilestore.get_all())
     self.assertEqual(len(tiles), 2)
     self.assertEqual(tiles[0].tilecoord, TileCoord(1, 0, 0))
     self.assertEqual(str(tiles[0].data), 'data')
     self.assertEqual(tiles[1].tilecoord, TileCoord(1, 0, 1))
     self.assertEqual(tiles[1].data, None)
     tilestream = [Tile(TileCoord(1, 0, 0))]
     tilestream = tilestore.delete(tilestream)
     consume(tilestream, None)
     self.assertEqual(len(tilestore), 1)
     tiles = list(tilestore.get_all())
     self.assertEqual(len(tiles), 1)
     self.assertFalse(Tile(TileCoord(1, 0, 0)) in tilestore)
     self.assertTrue(Tile(TileCoord(1, 0, 1)) in tilestore)
Esempio n. 2
0
def main(argv):
    # Create our RenderingTheWorld tile store that will manage the queue and subdivision.
    # We pass it the function that decides whether a tile should be subdivided, and an initial tile.
    rendering_the_world_tilestore = RenderingTheWorldTileStore(subdivide, seeds=(Tile(TileCoord(0, 0, 0)),))
    # Start the tilestream by getting a list of all tiles to be generated.
    tilestream = rendering_the_world_tilestore.list()
    tilestream = imap(Logger(logger, logging.INFO, 'get %(tilecoord)s'), tilestream)
    # Create the tile store that will generate our tiles, in this case it's a demo WMTS server at OpenGeo.
    # Getting tiles from this store will either return the tile as a PNG file, or set an error on the tile if there are no features in this tile.
    generate_tilestore = WMTSTileStore(
        url='http://v2.suite.opengeo.org/geoserver/gwc/service/wmts/',
        layer='medford:buildings',
        style='_null',
        format='image/png',
        tile_matrix_set='EPSG:900913',
        tile_matrix=lambda z: 'EPSG:900913:%d' % (z,))
    tilestream = generate_tilestore.get(tilestream)
    tilestream = imap(Logger(logger, logging.INFO, 'got %(tilecoord)s, error=%(error)s'), tilestream)
    # Put the tile back into the RenderingTheWorld tile store.  This check whether the tile should be subdivided, and, if so, adds the tile's children to the list of tiles to be generated.
    tilestream = rendering_the_world_tilestore.put(tilestream)
    # Get rid of tiles that returned an error (i.e. where there was no data).
    tilestream = imap(DropErrors(), tilestream)
    # Store the generated tiles in the output tile store, in our case a local MBTiles file.
    output_tilestore = MBTilesTileStore(sqlite3.connect('medford_buildings.mbtiles'))
    tilestream = output_tilestore.put(tilestream)
    tilestream = imap(Logger(logger, logging.INFO, 'saved %(tilecoord)s'), tilestream)
    # Go!
    consume(tilestream, None)
Esempio n. 3
0
 def test_one(self):
     tilestore = MBTilesTileStore(sqlite3.connect(':memory:'),
                                  content_type='image/png')
     self.assertEqual(len(tilestore), 0)
     tilestream = [
         Tile(TileCoord(1, 0, 0), data='data'), None,
         Tile(TileCoord(1, 0, 1), error=True)
     ]
     tilestream = tilestore.put(tilestream)
     tiles = list(tilestream)
     self.assertEqual(len(tilestore), 2)
     self.assertEqual(len(tiles), 2)
     self.assertEqual(tiles[0].tilecoord, TileCoord(1, 0, 0))
     self.assertEqual(tiles[0].data, 'data')
     self.assertEqual(tiles[1].tilecoord, TileCoord(1, 0, 1))
     self.assertEqual(tiles[1].error, True)
     self.assertTrue(Tile(TileCoord(1, 0, 0)) in tilestore)
     self.assertTrue(Tile(TileCoord(1, 0, 1)) in tilestore)
     tilestream = [Tile(TileCoord(1, 0, 0)), Tile(TileCoord(1, 0, 1))]
     tilestream = tilestore.get(tilestream)
     consume(tilestream, None)
     self.assertEqual(tilestore.get_cheap_bounding_pyramid(),
                      BoundingPyramid({1: (Bounds(0, 1), Bounds(0, 2))}))
     self.assertEqual(len(tilestore), 2)
     tiles = list(tilestore.list())
     self.assertEqual(len(tiles), 2)
     tiles = sorted(tilestore.get_all())
     self.assertEqual(len(tiles), 2)
     self.assertEqual(tiles[0].tilecoord, TileCoord(1, 0, 0))
     self.assertEqual(str(tiles[0].data), 'data')
     self.assertEqual(tiles[1].tilecoord, TileCoord(1, 0, 1))
     self.assertEqual(tiles[1].data, None)
     tilestream = [Tile(TileCoord(1, 0, 0))]
     tilestream = tilestore.delete(tilestream)
     consume(tilestream, None)
     self.assertEqual(len(tilestore), 1)
     tiles = list(tilestore.get_all())
     self.assertEqual(len(tiles), 1)
     self.assertFalse(Tile(TileCoord(1, 0, 0)) in tilestore)
     self.assertTrue(Tile(TileCoord(1, 0, 1)) in tilestore)