mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 02:41:09 +00:00
38 lines
1.4 KiB
Python
Executable File
38 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
#pmtiles to files
|
|
import argparse
|
|
import os
|
|
import shutil
|
|
|
|
from pmtiles.convert import mbtiles_to_pmtiles, pmtiles_to_mbtiles, pmtiles_to_dir
|
|
|
|
parser = argparse.ArgumentParser(description='Convert between PMTiles and other archive formats.')
|
|
parser.add_argument('input',help='Input .mbtiles or .pmtiles')
|
|
parser.add_argument('output',help='Output .mbtiles, .pmtiles, or directory')
|
|
parser.add_argument('--maxzoom', help='the maximum zoom level to include in the output.')
|
|
parser.add_argument('--gzip', help='Add gzip encoding to the output if it is not already gzipped.',action='store_true')
|
|
parser.add_argument('--overwrite', help='Overwrite the existing output.',action='store_true')
|
|
args = parser.parse_args()
|
|
|
|
if os.path.exists(args.output) and not args.overwrite:
|
|
print("Output exists, use --overwrite to overwrite the output.")
|
|
exit(1)
|
|
if args.overwrite:
|
|
if os.path.isfile(args.output):
|
|
os.remove(args.output)
|
|
elif os.path.isdir(args.output):
|
|
shutil.rmtree(args.output)
|
|
|
|
if args.input.endswith('.mbtiles') and args.output.endswith('.pmtiles'):
|
|
mbtiles_to_pmtiles(args.input, args.output, args.maxzoom)
|
|
|
|
elif args.input.endswith('.pmtiles') and args.output.endswith('.mbtiles'):
|
|
pmtiles_to_mbtiles(args.input, args.output, args.gzip)
|
|
|
|
elif args.input.endswith(".pmtiles"):
|
|
pmtiles_to_dir(args.input, args.output, args.gzip)
|
|
|
|
else:
|
|
print("Conversion not implemented")
|