forked from dandye/mbutil
-
Notifications
You must be signed in to change notification settings - Fork 10
/
mb-util
executable file
·67 lines (52 loc) · 2.25 KB
/
mb-util
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/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__':
logging.basicConfig(level=logging.DEBUG)
parser = optparse.OptionParser(usage="""usage: %prog [options] input output
Examples:
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
"arcgis" z/y/x with flipped y coordinate using ArcGIS hex naming convention""")
# 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)',
type='string',
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')
sys.exit(1)
# 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')
sys.exit(1)
# 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__)
else:
parser.print_help()