source: genesis/tools/fetch_bigmap_region.py

Last change on this file was 14314, checked in by rick, 6 years ago

Add crude attempt of creating A1 size nodemap picture

  • Property svn:executable set to *
File size: 1.5 KB
Line 
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
4import io, urllib2, datetime, time, re, random
5from 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)
9layers = ["http://tile.openstreetmap.org/!z/!x/!y.png"]
10attribution = 'Map data (c) OpenStreetMap'
11xsize = xmax - xmin + 1
12ysize = ymax - ymin + 1
13
14resultImage = Image.new("RGBA", (xsize * 256, ysize * 256), (0,0,0,0))
15counter = 0
16for 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
37draw = ImageDraw.Draw(resultImage)
38draw.text((5, ysize*256-15), attribution, (0,0,0))
39del draw
40
41now = datetime.datetime.now()
42outputFileName = "map%02d-%02d%02d%02d-%02d%02d.png" % (zoom, now.year % 100, now.month, now.day, now.hour, now.minute)
43resultImage.save(outputFileName)
Note: See TracBrowser for help on using the repository browser.