forked from vvoovv/tile-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stitch.py
34 lines (27 loc) · 1.32 KB
/
stitch.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
#!/usr/bin/env python
# Example parameters
# python stitch.py 26.7188,58.3786,26.72067,58.3791 bing
# python stitch.py 26.7188,58.3786,26.72067,58.3791 http://{a,b,c}.tile.openstreetmap.org
# python stitch.py -- -77.0471,38.8790,-77.0299,38.8891 ..\tiles.mbtiles
import sys, os, argparse, logging
from bing_aerial import BingAerial
from osm_tiles import OsmTiles
from mbtiles import Mbtiles
parser = argparse.ArgumentParser()
parser.add_argument("bbox", help="area bbox coordinates in the form left,bottom,right,top; example: 26.7188,58.3786,26.72067,58.3791")
parser.add_argument("source", help="source for tiles; example values: bing, http://{a,b,c}.tile.openstreetmap.org, pathTo/fileName.mbtiles")
parser.add_argument("-z", "--zoom", type=int, help="desired zoom")
parser.add_argument("-o", "--output", help="result image name, extension (.png or .jpg) defines image format type")
args = parser.parse_args()
# preparing bbox
bbox = [float(i) for i in args.bbox.split(",")]
if args.source == "bing":
tiles = BingAerial()
elif len(args.source)>7 and args.source[:7] == "http://":
tiles = OsmTiles(args.source)
elif len(args.source)>8 and os.path.isfile(args.source) and args.source[-8:] == ".mbtiles":
tiles = Mbtiles(args.source)
else:
logging.error("Unknown tile source")
sys.exit(-1)
tiles.stitch(bbox, args.zoom, output=args.output)