예제 #1
0
def test_mbtiles_to_disk_with_bad_zoom():
    fill_mbtiles('test/output/fill.mbtiles', 'test/data/tile.png', min_zoom=0, max_zoom=2, bbox='-180,-90,180,90')
    assert os.path.exists('test/output/fill.mbtiles')
    mbtiles_to_disk('test/output/fill.mbtiles', 'test/output', zoom=3)
    assert os.path.exists('test/output/metadata.json')
    assert not os.path.exists('test/output/tiles/0/0/0.png')
    assert not os.path.exists('test/output/tiles/3/0/0.png')
예제 #2
0
def test_mbtiles_fill_flipy():
    fill_mbtiles('test/output/fill.mbtiles', 'test/data/tile.png', zoom=1, tile_bbox='0,0,1,0', flip_y=True)
    assert os.path.exists('test/output/fill.mbtiles')
    mbtiles_to_disk('test/output/fill.mbtiles', 'test/output')
    assert os.path.exists('test/output/tiles/1/0/1.png')
    assert os.path.exists('test/output/tiles/1/1/1.png')
    assert not os.path.exists('test/output/tiles/1/0/0.png')
    assert not os.path.exists('test/output/tiles/1/1/0.png')
예제 #3
0
파일: test.py 프로젝트: BrunoSalerno/mbutil
def test_utf8grid_disk_to_mbtiles():
    os.mkdir('test/output')
    mbtiles_to_disk('test/data/utf8grid.mbtiles', 'test/output/original', callback=None)
    disk_to_mbtiles('test/output/original/', 'test/output/imported.mbtiles')
    mbtiles_to_disk('test/output/imported.mbtiles', 'test/output/imported', callback=None)
    assert os.path.exists('test/output/imported/0/0/0.grid.json')
    original = json.load(open('test/output/original/0/0/0.grid.json'))
    imported = json.load(open('test/output/imported/0/0/0.grid.json'))
    assert original['data']['77'] == imported['data']['77'] == {u'ISO_A2': u'FR'}
예제 #4
0
파일: test.py 프로젝트: BrunoSalerno/mbutil
def test_mbtiles_to_disk_utfgrid_callback():
    os.mkdir('test/output')
    callback = {}
    for c in ['null', 'foo']:
        mbtiles_to_disk('test/data/utf8grid.mbtiles', 'test/output/%s' % c, callback=c)
        f = open('test/output/%s/0/0/0.grid.json' % c)
        callback[c] = f.read().split('{')[0]
        f.close()
    assert callback['foo'] == 'foo('
    assert callback['null'] == ''
예제 #5
0
def test_mbtiles_fill_min_max_flipy():
    fill_mbtiles('test/output/fill.mbtiles', 'test/data/tile.png', min_zoom=1, max_zoom=2, bbox='0.1,0.1,180,90', flip_y=True)
    assert os.path.exists('test/output/fill.mbtiles')
    mbtiles_to_disk('test/output/fill.mbtiles', 'test/output')
    assert os.path.exists('test/output/tiles/1/1/1.png')
    assert not os.path.exists('test/output/tiles/1/0/0.png')
    assert not os.path.exists('test/output/tiles/1/1/0.png')
    assert not os.path.exists('test/output/tiles/1/2/1.png')
    assert os.path.exists('test/output/tiles/2/2/2.png')
    assert os.path.exists('test/output/tiles/2/2/3.png')
    assert os.path.exists('test/output/tiles/2/3/2.png')
    assert os.path.exists('test/output/tiles/2/3/3.png')
    assert not os.path.exists('test/output/tiles/2/2/1.png')
    assert not os.path.exists('test/output/tiles/2/1/1.png')
    assert not os.path.exists('test/output/tiles/2/0/0.png')
예제 #6
0
파일: test.py 프로젝트: Fil/mbutil
def test_utf8grid_mbtiles_to_disk():
    mbtiles_to_disk('test/data/utf8grid.mbtiles', 'test/output')
    assert os.path.exists('test/output/0/0/0.grid.json')
    assert os.path.exists('test/output/0/0/0.png')
    assert os.path.exists('test/output/metadata.json')
예제 #7
0
파일: test.py 프로젝트: Fil/mbutil
def test_mbtiles_to_disk_and_back():
    mbtiles_to_disk('test/data/one_tile.mbtiles', 'test/output')
    assert os.path.exists('test/output/0/0/0.png')
    disk_to_mbtiles('test/output/', 'test/output/one.mbtiles')
    assert os.path.exists('test/output/one.mbtiles')
예제 #8
0
파일: test.py 프로젝트: Fil/mbutil
def test_mbtiles_to_disk():
    mbtiles_to_disk('test/data/one_tile.mbtiles', 'test/output')
    assert os.path.exists('test/output/0/0/0.png')
    assert os.path.exists('test/output/metadata.json')
예제 #9
0
 def extract(self):
     with nostdout():
         mbtiles_to_disk(self.path, os.path.join(self.tmpdir, self.subdir), **{'scheme': self.scheme})
     return self.tmpdir
예제 #10
0
파일: mbutil.py 프로젝트: joenall/mbutil

if __name__ == '__main__':

    logging.basicConfig(level=logging.DEBUG)

    parser = OptionParser(usage="usage: %prog [options] input output")
    parser.add_option('-w', '--window', dest='window',
        help='compression window size. larger values faster, dangerouser',
        type='int',
        default=2000)

    (options, args) = parser.parse_args()

    # Transfer operations
    if len(args) == 2:
        if os.path.isfile(args[0]) and os.path.exists(args[1]):
            sys.stderr.write('To export MBTiles to disk, specify a directory that does not yet exist\n')
            sys.exit(1)
        if os.path.isfile(args[0]) and not os.path.exists(args[1]):
            mbtiles_file, directory_path = args
            mbtiles_to_disk(mbtiles_file, directory_path)
        if os.path.isdir(args[0]) and os.path.isfile(args[1]):
            sys.stderr.write('Importing tiles into already-existing MBTiles is not yet supported\n')
            sys.exit(1)
        if os.path.isdir(args[0]) and not os.path.isfile(args[0]):
            directory_path, mbtiles_file = args
            disk_to_mbtiles(directory_path, mbtiles_file)
    else:
        parser.print_help()
예제 #11
0
from mbutil import mbtiles_to_disk

logging.basicConfig(level=logging.DEBUG)

KEY = 'gnk8fnku3lwbxjz1fz34xx32'

# use png extension instead of jpeg
# jpeg will actually be downloaded but extension is png which won't break
# mbutil
url = "http://gpp3-wxs.ign.fr/%s/wmts?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&LAYER=GEOGRAPHICALGRIDSYSTEMS.MAPS&STYLE=normal&FORMAT=image/jpeg&TILEMATRIXSET=PM&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}.png" % KEY

filepath = "ign.mbtiles"
mb = MBTilesBuilder(cache=True, tiles_url=url, tiles_headers={'Referer': 'localhost'}, filepath=filepath)

if os.path.exists(mb.filepath):
    if os.path.exists(mb.cache.folder):
        shutil.rmtree(mb.cache.folder)
    mbtiles_to_disk(mb.filepath, mb.cache.folder)

f = file('ign2mbtiles.geojson', 'r')
boxes_as_geojson = f.read()
features = geojson.loads(boxes_as_geojson).features

zooms = [11, 13, 15]

for feature in features:
    bbox = shape(feature.geometry).bounds
    mb.add_coverage(bbox=bbox, zoomlevels=zooms)

mb.run(force=True)
예제 #12
0
파일: test.py 프로젝트: jaakla/mbutil
def test_disk_to_mbtiles_zyx():
    os.mkdir('test/output')
    disk_to_mbtiles('test/data/tiles/zyx', 'test/output/zyx.mbtiles', scheme='zyx', format='png')
    mbtiles_to_disk('test/output/zyx.mbtiles', 'test/output/tiles', callback=None)
    assert os.path.exists('test/output/tiles/3/1/5.png')
def test_mbtiles_to_disk():
    mbtiles_to_disk('test/data/one_tile.mbtiles', 'test/output')
    assert os.path.exists('test/output/0/0/0.png')
    assert os.path.exists('test/output/metadata.json')
def kap_px_to_ll(x, y):
    return polytrans(pwx, (x, y)), polytrans(pwy, (x, y))

# all 6 points are needed to handle polyconic projections
ll_range = kap_px_to_ll(0, 0),          kap_px_to_ll(kap_width, 0), \
           kap_px_to_ll(0, kap_height), kap_px_to_ll(kap_width, kap_height), \
           kap_px_to_ll(kap_width/2, 0), kap_px_to_ll(kap_width/2, kap_height) \

ll_min = map(min, apply(zip, ll_range))
ll_max = map(max, apply(zip, ll_range))

# read existing mbtiles
tiles_dir = tempfile.mkdtemp()
if os.path.exists(sys.argv[2]):
    os.rmdir(tiles_dir)
    mbtiles_to_disk(sys.argv[2], tiles_dir)
    os.remove(sys.argv[2])
    os.remove(tiles_dir + "/metadata.json")

tile_size = 256
proj = GoogleProjection(tile_size, range(0, 21))

# compute zoom level
px0=proj.project_pixels(ll_min, 20)
px1=proj.project_pixels(ll_max, 20)

plypx = map(kap_ll_to_px, ply)
lplypx = []
for p in plypx:
    lplypx.extend(p)