1 | #!/usr/bin/env python
|
---|
2 | # Generated by BigMap 2. Permalink: http://bigmap.osmz.ru/bigmap.php?xmin=8379&xmax=8417&ymin=5390&ymax=5416&zoom=14&scale=64&tiles=mapnik
|
---|
3 |
|
---|
4 | import io, urllib2, datetime, time, re, random
|
---|
5 | from PIL import Image, ImageDraw
|
---|
6 | # ^^^^^^ install "python-pillow" package | pip install Pillow | easy_install Pillow
|
---|
7 |
|
---|
8 | (zoom, xmin, ymin, xmax, ymax) = (14, 8379, 5390, 8417, 5416)
|
---|
9 | layers = ["http://tile.openstreetmap.org/!z/!x/!y.png"]
|
---|
10 | attribution = 'Map data (c) OpenStreetMap'
|
---|
11 | xsize = xmax - xmin + 1
|
---|
12 | ysize = ymax - ymin + 1
|
---|
13 |
|
---|
14 | resultImage = Image.new("RGBA", (xsize * 256, ysize * 256), (0,0,0,0))
|
---|
15 | counter = 0
|
---|
16 | for x in range(xmin, xmax+1):
|
---|
17 | for y in range(ymin, ymax+1):
|
---|
18 | for layer in layers:
|
---|
19 | url = layer.replace("!x", str(x)).replace("!y", str(y)).replace("!z", str(zoom))
|
---|
20 | match = re.search("{([a-z0-9]+)}", url)
|
---|
21 | if match:
|
---|
22 | url = url.replace(match.group(0), random.choice(match.group(1)))
|
---|
23 | print url, "... ";
|
---|
24 | try:
|
---|
25 | req = urllib2.Request(url, headers={'User-Agent': 'BigMap/2.0'})
|
---|
26 | tile = urllib2.urlopen(req).read()
|
---|
27 | except Exception, e:
|
---|
28 | print "Error", e
|
---|
29 | continue;
|
---|
30 | image = Image.open(io.BytesIO(tile))
|
---|
31 | resultImage.paste(image, ((x-xmin)*256, (y-ymin)*256), image.convert("RGBA"))
|
---|
32 | counter += 1
|
---|
33 | if counter == 10:
|
---|
34 | time.sleep(2);
|
---|
35 | counter = 0
|
---|
36 |
|
---|
37 | draw = ImageDraw.Draw(resultImage)
|
---|
38 | draw.text((5, ysize*256-15), attribution, (0,0,0))
|
---|
39 | del draw
|
---|
40 |
|
---|
41 | now = datetime.datetime.now()
|
---|
42 | outputFileName = "map%02d-%02d%02d%02d-%02d%02d.png" % (zoom, now.year % 100, now.month, now.day, now.hour, now.minute)
|
---|
43 | resultImage.save(outputFileName)
|
---|