Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: bf37bd7e2f
Fetching contributors…

Cannot retrieve contributors at this time

executable file 67 lines (51 sloc) 2.218 kb
#!/usr/bin/env python
# MBUtil: a tool for MBTiles files
# Supports importing, exporting, and more
# (c) Development Seed 2011
# Licensed under BSD
import logging
import os, sys
#from optparse import OptionParser
import optparse
from mbutil import mbtiles_to_disk, disk_to_mbtiles
if __name__ == '__main__':
parser = optparse.OptionParser(usage="""usage: %prog [options] input output
Export an mbtiles file to a directory of files:
$ mb-util world.mbtiles tiles # tiles must not alredy exist
Import a directory of tiles into an mbtiles file:
$ mb-util tiles world.mbtiles # mbtiles file must not already exist
Scheme Options are:
"tms" z/x/y (Default)
"osm" z/x/y with flipped y coordinate
"weogeo" z/y/x with flipped y coordinate""")
# todo - add support for compression
#parser.add_option('-w', '--window', dest='window',
# help='compression window size. larger values faster, dangerouser',
# type='int',
# default=2000)
parser.add_option('--scheme', dest='scheme',
help='Tiling scheme for exporting tiles. (Default=tms)',
(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')
# to disk
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, **options.__dict__)
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')
# to mbtiles
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, **options.__dict__)
Jump to Line
Something went wrong with that request. Please try again.