Beispiel #1
0
    def test_create(self):
        # Make a new file if it doesn't exist
        os.remove(self.tempfile.name)
        storage = MbtilesStorage.create(renderer=self.renderer,
                                        filename=self.tempfile.name,
                                        metadata=self.metadata)
        self.assertEqual(storage.filename, self.tempfile.name)
        self.assertEqual(storage.mbtiles.metadata, self.metadata)
        self.assertTrue(os.path.isfile(self.tempfile.name))

        # Make a duplicate file
        MbtilesStorage.create(renderer=self.renderer,
                              filename=self.tempfile.name,
                              metadata=self.metadata)
        self.assertEqual(storage.filename, self.tempfile.name)
        self.assertTrue(os.path.isfile(self.tempfile.name))
 def test_zoom_offset(self):
     with NamedTemporaryFile(suffix='.mbtiles') as outputfile:
         metadata = dict(
             name='bluemarble-aligned',
             type='baselayer',
             version='1.0.0',
             description='BlueMarble 2004-07 Aligned',
             format='png',
         )
         warp_mbtiles(inputfile=self.inputfile,
                      outputfile=outputfile.name,
                      metadata=metadata,
                      min_resolution=0,
                      max_resolution=3,
                      zoom_offset=2,
                      renderer=TouchRenderer(suffix='.png'))
         with MbtilesStorage(renderer=None,
                             filename=outputfile.name) as storage:
             self.assertEqual(
                 set((z, x, y) for z, x, y, data in storage.mbtiles.all()),
                 set([(2, 0, 0)] + [(3, x, y) for x in range(0, 2)
                                    for y in range(0, 2)] +
                     [(4, x, y) for x in range(0, 4)
                      for y in range(0, 4)] + [(5, x, y)
                                               for x in range(0, 8)
                                               for y in range(0, 8)]))
             self.assertEqual(storage.mbtiles.metadata['bounds'],
                              '-180.0,-90.0,0.0,0.0')
             self.assertEqual(storage.mbtiles.metadata['x-minzoom'], '2')
             self.assertEqual(storage.mbtiles.metadata['x-maxzoom'], '5')
Beispiel #3
0
    def test_save(self):
        # We must create this on disk
        self.storage = MbtilesStorage.create(renderer=self.renderer,
                                             filename=self.tempfile.name,
                                             metadata=self.metadata)

        # Transparent 1×1 image
        image = VImage.new_rgba(width=1, height=1,
                                ink=rgba(r=0, g=0, b=0, a=0))

        # Save it twice, assuming that MBTiles will deduplicate
        self.storage.save(x=0, y=1, z=2, image=image)
        self.storage.save(x=1, y=0, z=2, image=image)
        self.storage.waitall()

        # Assert that things were saved properly
        self.assertEqual(
            [(z, x, y, intmd5(data))
             for z, x, y, data in self.storage.mbtiles.all()],
            [
                (2, 0, 1, 89446660811628514001822794642426893173),
                (2, 1, 0, 89446660811628514001822794642426893173),
            ]
        )

        # Close the existing database.
        self.storage.mbtiles.close()

        # Re-open the created file
        storage = MbtilesStorage(renderer=self.renderer,
                                 filename=self.tempfile.name)

        # Read out of the backend
        self.assertEqual(
            [(z, x, y, intmd5(data))
             for z, x, y, data in storage.mbtiles.all()],
            [
                (2, 0, 1, 89446660811628514001822794642426893173),
                (2, 1, 0, 89446660811628514001822794642426893173),
            ]
        )
Beispiel #4
0
 def setUp(self):
     self.tempfile = NamedTemporaryFile()
     # Use the PngRenderer because we want to know that callback
     # works properly.
     self.renderer = PngRenderer(png8=False, optimize=False)
     self.metadata = dict(
         name='transparent',
         type=Metadata.latest().TYPES.BASELAYER,
         version='1.0.0',
         description='Transparent World 2012',
         format=Metadata.latest().FORMATS.PNG,
     )
     self.storage = MbtilesStorage.create(renderer=self.renderer,
                                          filename=':memory:',
                                          metadata=self.metadata)