forked from gsi-cyberjapan/vector_tiles_convert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gjson2mvt.py
46 lines (37 loc) · 1.2 KB
/
gjson2mvt.py
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
import os
from os import makedirs,listdir
from os.path import join,exists
from sys import exit
def mbtile(inpath,outpath,z):
_in = join(inpath,z,'*','*.geojson')
cmd = 'tippecanoe -o '+outpath+' -z '+z+' -Z '+z+' -ac -ar -ao -pp '+_in
print cmd
#os.system(cmd)
def pbf(inpath,outpath,z):
_in = join(inpath,z)
for yd in listdir(_in):
for xf in listdir(join(_in,yd)):
if not exists(join(outpath,z,yd)):
makedirs(join(outpath,z,yd))
nxf = xf.split('.')[0]+'.pbf'
cmd = 'json2geobuf '+join(_in,yd,xf)+' > '+join(outpath,z,yd,nxf)
print cmd
os.system(cmd)
def help():
print '''
python gjson2mvt.py mbtile|pbf in_base out_base z
in_base: path of base directory of input data
out_base: (mbtile) path of base directory of output data
(pbf) path of output file
z : zoom level
'''
if __name__ == '__main__':
from sys import argv
if not len(argv) == 5:
help()
exit()
assert(argv[1] == 'mbtile' or argv[1] == 'pbf')
if argv[1] == 'mbtile':
mbtile(argv[2],argv[3],argv[4])
elif argv[1] == 'pbf':
pbf(argv[2],argv[3],argv[4])