コード例 #1
0
    def test_save(self):
        image = VImage.new_rgba(width=1, height=1,
                                ink=rgba(r=0, g=0, b=0, a=0))
        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()
        self.assertEqual(set(os.listdir(self.outputdir)),
                         set([
                             '2-0-1-f1d3ff8443297732862df21dc4e57262.png',
                             '2-1-0-f1d3ff8443297732862df21dc4e57262.png'
                         ]))

        # Is this a real file?
        self.assertFalse(
            os.path.islink(os.path.join(
                self.outputdir, '2-0-1-f1d3ff8443297732862df21dc4e57262.png'
            ))
        )

        # Does the symlinking work?
        self.assertEqual(
            os.readlink(os.path.join(
                self.outputdir, '2-1-0-f1d3ff8443297732862df21dc4e57262.png'
            )),
            '2-0-1-f1d3ff8443297732862df21dc4e57262.png'
        )
コード例 #2
0
    def test_simple(self):
        renderer = JpegRenderer()

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

        black = renderer.render(image=image)
        black_md5 = intmd5(black)

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

        transparent = renderer.render(image=image)
        self.assertEqual(intmd5(transparent), black_md5)
コード例 #3
0
    def test_shrink(self):
        image = VImage.new_rgba(width=16, height=16)

        # No shrink
        shrunk = image.shrink(xscale=1.0, yscale=1.0)
        self.assertEqual(shrunk.Xsize(), image.Xsize())
        self.assertEqual(shrunk.Ysize(), image.Ysize())

        # X direction
        shrunk = image.shrink(xscale=0.25, yscale=1.0)
        self.assertEqual(shrunk.Xsize(), image.Xsize() * 0.25)
        self.assertEqual(shrunk.Ysize(), image.Ysize())

        # Y direction
        shrunk = image.shrink(xscale=1.0, yscale=0.5)
        self.assertEqual(shrunk.Xsize(), image.Xsize())
        self.assertEqual(shrunk.Ysize(), image.Ysize() * 0.5)

        # Both directions
        shrunk = image.shrink(xscale=0.25, yscale=0.5)
        self.assertEqual(shrunk.Xsize(), image.Xsize() * 0.25)
        self.assertEqual(shrunk.Ysize(), image.Ysize() * 0.5)

        # Not a power of 2
        shrunk = image.shrink(xscale=0.0625, yscale=0.125)
        self.assertEqual(shrunk.Xsize(), int(image.Xsize() * 0.0625))
        self.assertEqual(shrunk.Ysize(), int(image.Ysize() * 0.125))

        # Out of bounds
        self.assertRaises(ValueError, image.shrink, xscale=0.0, yscale=1.0)
        self.assertRaises(ValueError, image.shrink, xscale=2.0, yscale=1.0)
        self.assertRaises(ValueError, image.shrink, xscale=1.0, yscale=0.0)
        self.assertRaises(ValueError, image.shrink, xscale=1.0, yscale=2.0)
コード例 #4
0
    def test_upsample(self):
        resolution = 0
        image = VImage.new_rgba(width=TILE_SIDE * 2**resolution,
                                height=TILE_SIDE * 2**resolution)
        tiles = TmsTiles(image=image,
                         storage=Storage(renderer=None),
                         tile_width=TILE_SIDE,
                         tile_height=TILE_SIDE,
                         offset=XY(0, 0),
                         resolution=resolution)

        # Zero levels
        self.assertRaises(AssertionError, tiles.upsample, levels=0)

        # One level
        tiles1a = tiles.upsample()
        self.assertEqual(tiles1a.image_width, TILE_SIDE * 2**(resolution + 1))
        self.assertEqual(tiles1a.image_height, TILE_SIDE * 2**(resolution + 1))
        self.assertEqual(tiles1a.resolution, resolution + 1)

        tiles1b = tiles.upsample(levels=1)
        self.assertEqual(tiles1b.image_width, TILE_SIDE * 2**(resolution + 1))
        self.assertEqual(tiles1b.image_height, TILE_SIDE * 2**(resolution + 1))
        self.assertEqual(tiles1b.resolution, resolution + 1)

        # Two levels
        tiles2 = tiles.upsample(levels=2)
        self.assertEqual(tiles2.image_width, TILE_SIDE * 2**(resolution + 2))
        self.assertEqual(tiles2.image_height, TILE_SIDE * 2**(resolution + 2))
        self.assertEqual(tiles2.resolution, resolution + 2)
コード例 #5
0
    def test_stretch(self):
        image = VImage.new_rgba(width=16, height=16)

        # No stretch
        stretched = image.stretch(xscale=1.0, yscale=1.0)
        self.assertEqual(stretched.Xsize(), image.Xsize())
        self.assertEqual(stretched.Ysize(), image.Ysize())

        # X direction
        stretched = image.stretch(xscale=2.0, yscale=1.0)
        self.assertEqual(stretched.Xsize(), image.Xsize() * 2.0)
        self.assertEqual(stretched.Ysize(), image.Ysize())

        # Y direction
        stretched = image.stretch(xscale=1.0, yscale=4.0)
        self.assertEqual(stretched.Xsize(), image.Xsize())
        self.assertEqual(stretched.Ysize(), image.Ysize() * 4.0)

        # Both directions
        stretched = image.stretch(xscale=2.0, yscale=4.0)
        self.assertEqual(stretched.Xsize(), image.Xsize() * 2.0)
        self.assertEqual(stretched.Ysize(), image.Ysize() * 4.0)

        # Not a power of 2
        stretched = image.stretch(xscale=3.0, yscale=5.0)
        self.assertEqual(stretched.Xsize(), image.Xsize() * 3.0)
        self.assertEqual(stretched.Ysize(), image.Ysize() * 5.0)

        # Out of bounds
        self.assertRaises(ValueError, image.stretch, xscale=0.5, yscale=1.0)
        self.assertRaises(ValueError, image.stretch, xscale=1.0, yscale=0.5)
コード例 #6
0
ファイル: test_vips.py プロジェクト: mdupuis/gdal2mbtiles
    def test_stretch(self):
        image = VImage.new_rgba(width=16, height=16)

        # No stretch
        stretched = image.stretch(xscale=1.0, yscale=1.0)
        self.assertEqual(stretched.Xsize(), image.Xsize())
        self.assertEqual(stretched.Ysize(), image.Ysize())

        # X direction
        stretched = image.stretch(xscale=2.0, yscale=1.0)
        self.assertEqual(stretched.Xsize(), image.Xsize() * 2.0)
        self.assertEqual(stretched.Ysize(), image.Ysize())

        # Y direction
        stretched = image.stretch(xscale=1.0, yscale=4.0)
        self.assertEqual(stretched.Xsize(), image.Xsize())
        self.assertEqual(stretched.Ysize(), image.Ysize() * 4.0)

        # Both directions
        stretched = image.stretch(xscale=2.0, yscale=4.0)
        self.assertEqual(stretched.Xsize(), image.Xsize() * 2.0)
        self.assertEqual(stretched.Ysize(), image.Ysize() * 4.0)

        # Not a power of 2
        stretched = image.stretch(xscale=3.0, yscale=5.0)
        self.assertEqual(stretched.Xsize(), image.Xsize() * 3.0)
        self.assertEqual(stretched.Ysize(), image.Ysize() * 5.0)

        # Out of bounds
        self.assertRaises(ValueError,
                          image.stretch, xscale=0.5, yscale=1.0)
        self.assertRaises(ValueError,
                          image.stretch, xscale=1.0, yscale=0.5)
コード例 #7
0
    def test_save(self):
        image = VImage.new_rgba(width=1, height=1,
                                ink=rgba(r=0, g=0, b=0, a=0))
        self.storage.save(x=0, y=1, z=2, image=image)
        self.storage.save(x=1, y=0, z=2, image=image)
        self.storage.save(x=1, y=0, z=3, image=image)
        self.storage.waitall()
        self.assertEqual(set(recursive_listdir(self.outputdir)),
                         set(['2/',
                              '2/0/',
                              '2/0/1.png',
                              '2/1/',
                              '2/1/0.png',
                              '3/',
                              '3/1/',
                              '3/1/0.png']))

        # Is this a real file?
        self.assertFalse(
            os.path.islink(os.path.join(self.outputdir, '2', '0', '1.png'))
        )

        # Does the symlinking work?
        self.assertEqual(
            os.readlink(os.path.join(self.outputdir, '2', '1', '0.png')),
            os.path.join(os.path.pardir, '0', '1.png')
        )
        self.assertEqual(
            os.readlink(os.path.join(self.outputdir, '3', '1', '0.png')),
            os.path.join(os.path.pardir, os.path.pardir, '2', '0', '1.png')
        )
コード例 #8
0
    def test_simple(self):
        renderer = JpegRenderer()

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

        black = renderer.render(image=image)
        black_md5 = intmd5(black)

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

        transparent = renderer.render(image=image)
        self.assertEqual(intmd5(transparent), black_md5)
コード例 #9
0
ファイル: test_vips.py プロジェクト: mdupuis/gdal2mbtiles
 def test_buffer_size(self):
     image = VImage.new_rgba(width=16, height=16)
     self.assertEqual(
         image.BufferSize(),
         (16 *               # width
          16 *               # height
          4 *                # bands
          1)                 # data size
     )
コード例 #10
0
ファイル: test_vips.py プロジェクト: mdupuis/gdal2mbtiles
 def test_dimensions(self):
     # Very small WGS84 map. :-)
     image = VImage.new_rgba(width=2, height=1)
     tiles = TmsTiles(image=image,
                      storage=Storage(renderer=None),
                      tile_width=1, tile_height=1,
                      offset=XY(0, 0), resolution=0)
     self.assertEqual(tiles.image_width, 2)
     self.assertEqual(tiles.image_height, 1)
コード例 #11
0
 def test_buffer_size(self):
     image = VImage.new_rgba(width=16, height=16)
     self.assertEqual(
         image.BufferSize(),
         (
             16 *  # width
             16 *  # height
             4 *  # bands
             1)  # data size
     )
コード例 #12
0
    def test_write_to_tempfile(self):
        image = VImage.new_rgba(width=16, height=16)
        image2 = image.write_to_tempfile()
        tempfile = image2._buf
        self.assertEqual(image.tobuffer(), image2.tobuffer())

        # Does the file delete itself?
        self.assertTrue(os.path.exists(tempfile.name))
        tempfile.close()
        self.assertFalse(os.path.exists(tempfile.name))
コード例 #13
0
ファイル: test_vips.py プロジェクト: mdupuis/gdal2mbtiles
    def test_write_to_tempfile(self):
        image = VImage.new_rgba(width=16, height=16)
        image2 = image.write_to_tempfile()
        tempfile = image2._buf
        self.assertEqual(image.tobuffer(), image2.tobuffer())

        # Does the file delete itself?
        self.assertTrue(os.path.exists(tempfile.name))
        tempfile.close()
        self.assertFalse(os.path.exists(tempfile.name))
コード例 #14
0
 def test_dimensions(self):
     # Very small WGS84 map. :-)
     image = VImage.new_rgba(width=2, height=1)
     tiles = TmsTiles(image=image,
                      storage=Storage(renderer=None),
                      tile_width=1,
                      tile_height=1,
                      offset=XY(0, 0),
                      resolution=0)
     self.assertEqual(tiles.image_width, 2)
     self.assertEqual(tiles.image_height, 1)
コード例 #15
0
ファイル: test_vips.py プロジェクト: mdupuis/gdal2mbtiles
    def test_downsample(self):
        resolution = 2
        image = VImage.new_rgba(width=TILE_SIDE * 2 ** resolution,
                                height=TILE_SIDE * 2 ** resolution)
        tiles = TmsTiles(image=image,
                         storage=Storage(renderer=None),
                         tile_width=TILE_SIDE, tile_height=TILE_SIDE,
                         offset=XY(0, 0),
                         resolution=resolution)

        # Zero levels - invalid
        self.assertRaises(AssertionError,
                          tiles.downsample, levels=0)

        # One level
        tiles1a = tiles.downsample()
        self.assertEqual(tiles1a.image_width,
                         TILE_SIDE * 2 ** (resolution - 1))
        self.assertEqual(tiles1a.image_height,
                         TILE_SIDE * 2 ** (resolution - 1))
        self.assertEqual(tiles1a.resolution,
                         resolution - 1)

        tiles1b = tiles.downsample(levels=1)
        self.assertEqual(tiles1b.image_width,
                         TILE_SIDE * 2 ** (resolution - 1))
        self.assertEqual(tiles1b.image_height,
                         TILE_SIDE * 2 ** (resolution - 1))
        self.assertEqual(tiles1b.resolution,
                         resolution - 1)

        # Two levels
        tiles2 = tiles.downsample(levels=2)
        self.assertEqual(tiles2.image_width,
                         TILE_SIDE * 2 ** (resolution - 2))
        self.assertEqual(tiles2.image_height,
                         TILE_SIDE * 2 ** (resolution - 2))
        self.assertEqual(tiles2.resolution,
                         resolution - 2)

        # Three levels - invalid since resolution is 2
        self.assertRaises(AssertionError,
                          tiles.downsample, levels=3)
コード例 #16
0
ファイル: test_vips.py プロジェクト: mdupuis/gdal2mbtiles
    def test_tms_align(self):
        image = VImage.new_rgba(width=16, height=16)

        # Already aligned to integer offsets
        result = image.tms_align(tile_width=16, tile_height=16,
                                 offset=XY(1, 1))
        self.assertEqual(result.Xsize(), image.Xsize())
        self.assertEqual(result.Ysize(), image.Ysize())

        # Spanning by half tiles in both X and Y directions
        result = image.tms_align(tile_width=16, tile_height=16,
                                 offset=XY(1.5, 1.5))
        self.assertEqual(result.Xsize(), image.Xsize() * 2)
        self.assertEqual(result.Ysize(), image.Ysize() * 2)

        # Image is quarter tile
        result = image.tms_align(tile_width=32, tile_height=32,
                                 offset=XY(1, 1))
        self.assertEqual(result.Xsize(), image.Xsize() * 2)
        self.assertEqual(result.Ysize(), image.Ysize() * 2)
コード例 #17
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),
            ]
        )
コード例 #18
0
    def test_tms_align(self):
        image = VImage.new_rgba(width=16, height=16)

        # Already aligned to integer offsets
        result = image.tms_align(tile_width=16,
                                 tile_height=16,
                                 offset=XY(1, 1))
        self.assertEqual(result.Xsize(), image.Xsize())
        self.assertEqual(result.Ysize(), image.Ysize())

        # Spanning by half tiles in both X and Y directions
        result = image.tms_align(tile_width=16,
                                 tile_height=16,
                                 offset=XY(1.5, 1.5))
        self.assertEqual(result.Xsize(), image.Xsize() * 2)
        self.assertEqual(result.Ysize(), image.Ysize() * 2)

        # Image is quarter tile
        result = image.tms_align(tile_width=32,
                                 tile_height=32,
                                 offset=XY(1, 1))
        self.assertEqual(result.Xsize(), image.Xsize() * 2)
        self.assertEqual(result.Ysize(), image.Ysize() * 2)
コード例 #19
0
ファイル: test_vips.py プロジェクト: mdupuis/gdal2mbtiles
    def test_shrink(self):
        image = VImage.new_rgba(width=16, height=16)

        # No shrink
        shrunk = image.shrink(xscale=1.0, yscale=1.0)
        self.assertEqual(shrunk.Xsize(), image.Xsize())
        self.assertEqual(shrunk.Ysize(), image.Ysize())

        # X direction
        shrunk = image.shrink(xscale=0.25, yscale=1.0)
        self.assertEqual(shrunk.Xsize(), image.Xsize() * 0.25)
        self.assertEqual(shrunk.Ysize(), image.Ysize())

        # Y direction
        shrunk = image.shrink(xscale=1.0, yscale=0.5)
        self.assertEqual(shrunk.Xsize(), image.Xsize())
        self.assertEqual(shrunk.Ysize(), image.Ysize() * 0.5)

        # Both directions
        shrunk = image.shrink(xscale=0.25, yscale=0.5)
        self.assertEqual(shrunk.Xsize(), image.Xsize() * 0.25)
        self.assertEqual(shrunk.Ysize(), image.Ysize() * 0.5)

        # Not a power of 2
        shrunk = image.shrink(xscale=0.0625, yscale=0.125)
        self.assertEqual(shrunk.Xsize(), int(image.Xsize() * 0.0625))
        self.assertEqual(shrunk.Ysize(), int(image.Ysize() * 0.125))

        # Out of bounds
        self.assertRaises(ValueError,
                          image.shrink, xscale=0.0, yscale=1.0)
        self.assertRaises(ValueError,
                          image.shrink, xscale=2.0, yscale=1.0)
        self.assertRaises(ValueError,
                          image.shrink, xscale=1.0, yscale=0.0)
        self.assertRaises(ValueError,
                          image.shrink, xscale=1.0, yscale=2.0)
コード例 #20
0
 def test_get_hash(self):
     image = VImage.new_rgba(width=1, height=1,
                             ink=rgba(r=0, g=0, b=0, a=0))
     self.assertEqual(self.storage.get_hash(image=image),
                      long('f1d3ff8443297732862df21dc4e57262', base=16))
コード例 #21
0
 def setUp(self):
     # Transparent 1×1 image
     self.image = VImage.new_rgba(width=1,
                                  height=1,
                                  ink=rgba(r=0, g=0, b=0, a=0))
コード例 #22
0
 def test_new_rgba(self):
     image = VImage.new_rgba(width=1, height=2)
     self.assertEqual(image.Xsize(), 1)
     self.assertEqual(image.Ysize(), 2)
     self.assertEqual(image.Bands(), 4)
コード例 #23
0
 def test_from_vimage(self):
     image = VImage.new_rgba(width=1, height=1)
     self.assertEqual(
         VImage.from_vimage(image).tostring(), image.tostring())
コード例 #24
0
ファイル: test_vips.py プロジェクト: mdupuis/gdal2mbtiles
 def test_from_vimage(self):
     image = VImage.new_rgba(width=1, height=1)
     self.assertEqual(VImage.from_vimage(image).tostring(),
                      image.tostring())
コード例 #25
0
ファイル: test_vips.py プロジェクト: mdupuis/gdal2mbtiles
 def test_new_rgba(self):
     image = VImage.new_rgba(width=1, height=2)
     self.assertEqual(image.Xsize(), 1)
     self.assertEqual(image.Ysize(), 2)
     self.assertEqual(image.Bands(), 4)
コード例 #26
0
 def test_write_to_memory(self):
     image = VImage.new_rgba(width=16, height=16)
     image2 = image.write_to_memory()
     self.assertEqual(image.tobuffer(), image2.tobuffer())
コード例 #27
0
 def setUp(self):
     # Transparent 1×1 image
     self.image = VImage.new_rgba(width=1, height=1,
                                  ink=rgba(r=0, g=0, b=0, a=0))
コード例 #28
0
ファイル: test_vips.py プロジェクト: mdupuis/gdal2mbtiles
 def test_write_to_memory(self):
     image = VImage.new_rgba(width=16, height=16)
     image2 = image.write_to_memory()
     self.assertEqual(image.tobuffer(), image2.tobuffer())