-
Notifications
You must be signed in to change notification settings - Fork 0
/
bigmap.py
42 lines (37 loc) · 1.48 KB
/
bigmap.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
#!/usr/bin/env python
# Generated by BigMap 2. Permalink: http://bigmap.osmz.ru/bigmap.php?xmin=10432&xmax=10559&ymin=22848&ymax=22943&zoom=16&scale=256&tiles=mapnik
import io, urllib2, datetime, time, re, random
from PIL import Image, ImageDraw
# ^^^^^^ install "python-pillow" package | pip install Pillow | easy_install Pillow
(zoom, xmin, ymin, xmax, ymax) = (16, 10432, 22848, 10559, 22943)
layers = ["http://tile.openstreetmap.org/!z/!x/!y.png"]
attribution = 'Map data (c) OpenStreetMap'
xsize = xmax - xmin + 1
ysize = ymax - ymin + 1
resultImage = Image.new("RGBA", (xsize * 256, ysize * 256), (0,0,0,0))
counter = 0
for x in range(xmin, xmax+1):
for y in range(ymin, ymax+1):
for layer in layers:
url = layer.replace("!x", str(x)).replace("!y", str(y)).replace("!z", str(zoom))
match = re.search("{([a-z0-9]+)}", url)
if match:
url = url.replace(match.group(0), random.choice(match.group(1)))
print url, "... ";
try:
req = urllib2.Request(url, headers={'User-Agent': 'BigMap/2.0'})
tile = urllib2.urlopen(req).read()
except Exception, e:
print "Error", e
continue;
image = Image.open(io.BytesIO(tile))
resultImage.paste(image, ((x-xmin)*256, (y-ymin)*256), image.convert("RGBA"))
counter += 1
if counter == 10:
time.sleep(2);
counter = 0
draw = ImageDraw.Draw(resultImage)
draw.text((5, ysize*256-15), attribution, (0,0,0))
del draw
outputFileName = "Seattle.png"
resultImage.save(outputFileName)