def test_export_mbtiles_int_zoom(tmpdir): tpk = TPK("tests/data/states_filled.tpk") mbtiles_filename = str(tmpdir.join("test.mbtiles")) tpk.to_mbtiles(mbtiles_filename, zoom=1) tpk.close() assert os.path.exists(mbtiles_filename)
def test_alt_root_name(tmpdir): tpk = TPK("tests/data/alt_root_name.tpk") mbtiles_filename = str(tmpdir.join("test")) tpk.to_mbtiles(mbtiles_filename) tpk.close() assert os.path.exists("{0}.mbtiles".format(mbtiles_filename))
def test_export_mbtiles_add_suffix(tmpdir): tpk = TPK("tests/data/states_filled.tpk") mbtiles_filename = str(tmpdir.join("test")) tpk.to_mbtiles(mbtiles_filename) tpk.close() assert os.path.exists("{0}.mbtiles".format(mbtiles_filename))
def test_alt_root_name(tmpdir): tpk = TPK('tests/data/alt_root_name.tpk') mbtiles_filename = str(tmpdir.join('test')) tpk.to_mbtiles(mbtiles_filename) tpk.close() assert os.path.exists('{0}.mbtiles'.format(mbtiles_filename))
def test_export_disk_invalid_scheme(tmpdir): tpk = TPK("tests/data/states_filled.tpk") path = str(tmpdir.join("tiles")) with pytest.raises(ValueError): tpk.to_disk(path, scheme="bad") tpk.close()
def test_export_disk_mixed_format(tmpdir): tpk = TPK("tests/data/states_filled.tpk") tpk.format = "mixed" # this is a hack to make test fail, need a test file for this path = str(tmpdir.join("tiles")) with pytest.raises(ValueError): tpk.to_disk(path) tpk.close()
def test_export_disk_int_zoom(tmpdir): tpk = TPK("tests/data/states_filled.tpk") path = str(tmpdir.join("tiles")) tpk.to_disk(path, zoom=1) tpk.close() assert os.path.exists(path) assert os.path.exists(os.path.join(path, "1/0/0.png")) assert not os.path.exists(os.path.join(path, "0/0/0.png"))
def test_export_mbtiles_mixed_format(tmpdir): tpk = TPK('tests/data/states_filled.tpk') tpk.format = 'mixed' # this is a hack to make test fail, need a test file for this mbtiles_filename = str(tmpdir.join('test.mbtiles')) with pytest.raises(ValueError): tpk.to_mbtiles(mbtiles_filename) tpk.close()
def test_export_disk_existing_output(tmpdir): tpk = TPK("tests/data/states_filled.tpk") path = str(tmpdir.join("tiles")) os.makedirs(path) with open(os.path.join(path, "test.txt"), "w") as outfile: outfile.write("Foo") with pytest.raises(IOError): tpk.to_disk(path) tpk.close()
def test_export_disk_existing_output(tmpdir): tpk = TPK('tests/data/states_filled.tpk') path = str(tmpdir.join('tiles')) os.makedirs(path) with open(os.path.join(path, 'test.txt'), 'w') as outfile: outfile.write('Foo') with pytest.raises(IOError): tpk.to_disk(path) tpk.close()
def mbtiles(tpk_filename, mbtiles_filename, zoom, overwrite, verbose): """Export the tile package to mbtiles format""" configure_logging(verbose) if os.path.exists(mbtiles_filename) and not overwrite: raise click.ClickException('Output exists and overwrite is false. ' 'Use --overwrite option to overwrite') start = time.time() if zoom is not None: zoom = [int(v) for v in zoom.split(',')] tpk = TPK(tpk_filename) tpk.to_mbtiles(mbtiles_filename, zoom) tpk.close() print('Exported tiles in {0:2f} seconds'.format(time.time() - start))
def mbtiles(tpk_filename, mbtiles_filename, zoom, overwrite, drop_empty, tile_bounds, verbose): """Export the tile package to mbtiles format""" configure_logging(verbose) if os.path.exists(mbtiles_filename) and not overwrite: raise click.ClickException("Output exists and overwrite is false. " "Use --overwrite option to overwrite") start = time.time() if zoom is not None: zoom = [int(v) for v in zoom.split(",")] tpk = TPK(tpk_filename) tpk.to_mbtiles(mbtiles_filename, zoom=zoom, tile_bounds=tile_bounds, drop_empty=drop_empty) tpk.close() print("Exported tiles in {0:2f} seconds".format(time.time() - start))