├── tmp └── .gitignore ├── .gitignore ├── map.png ├── README.md └── image.py /tmp/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | karte.png 3 | -------------------------------------------------------------------------------- /map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ubahnverleih/Tiles2BigMap/master/map.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tiles2BigMap 2 | 3 | ## Installation 4 | 5 | Tiles2BigMap needs PIL. 6 | install PIL via `pip install PIL` 7 | or on OSX `brew install pil` 8 | 9 | ## Using 10 | 11 | * Go to [BigMap](http://openstreetmap.gryph.de/bigmap.html) Select an area, an click submit. 12 | * Copy URL 13 | * start Tiles2BigMap `python image.py -u ''` 14 | * if you installed PIL via brew, then you have to type in something like this `PYTHONPATH=/usr/local/Cellar/pil/1.1.7/lib/python2.7/site-packages/ python image.py -u ''` -------------------------------------------------------------------------------- /image.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | import urllib2 3 | from urlparse import urlparse, parse_qs 4 | from optparse import OptionParser 5 | 6 | 7 | 8 | #parse arguments 9 | parser = OptionParser() 10 | 11 | parser.add_option("-u", "--url", dest="url") 12 | parser.add_option("-o", "--outputfile", dest="output") 13 | 14 | (optionen, args) = parser.parse_args() 15 | 16 | 17 | 18 | # permalink for this map: http://openstreetmap.gryph.de/bigmap.cgi?xmin=8815&xmax=8818&ymin=5480&ymax=5482&zoom=14&scale=256&baseurl=http%3A%2F%2Ftile.openstreetmap.org%2F!z%2F!x%2F!y.png 19 | """ 20 | xmin = 8805; 21 | xmax = 8808; 22 | ymin = 5490; 23 | ymax = 5492; 24 | zoom = 14; 25 | scale = 256; 26 | tileserver = "http://tile.openstreetmap.org/!z/!x/!y.png"; #osm 27 | #tileserver = "http://otile1.mqcdn.com/tiles/1.0.0/map/!z/!x/!y.jpg"; #mapquest 28 | """ 29 | 30 | url = optionen.url 31 | 32 | #parse bigmap URL 33 | urlparams = parse_qs(urlparse(url).query) 34 | xmin = int(urlparams["xmin"][0]); 35 | xmax = int(urlparams["xmax"][0]); 36 | ymin = int(urlparams["ymin"][0]); 37 | ymax = int(urlparams["ymax"][0]); 38 | zoom = int(urlparams["zoom"][0]); 39 | try: 40 | scale = int(urlparams["scale"][0]); 41 | except: 42 | scale = 256 43 | tileserver = urlparams["baseurl"][0]; 44 | 45 | 46 | #Aus tileserver URL und tileinfos wird tileURL generiert 47 | def getTileURL(tileserver, x, y, z): 48 | tileserver = tileserver.replace("!x",str(x)) 49 | tileserver = tileserver.replace("!y",str(y)) 50 | tileserver = tileserver.replace("!z",str(z)) 51 | return tileserver 52 | 53 | 54 | 55 | 56 | 57 | 58 | width = (xmax-xmin)*scale; 59 | height = (ymax-ymin)*scale; 60 | 61 | size = width, height 62 | 63 | mainimage = Image.new("RGB", size); 64 | 65 | for x in range(xmin, xmax): 66 | xanz = x - xmin; #das wie vielte Bild (x) 67 | for y in range(ymin, ymax): 68 | yanz = y - ymin; #das wie vielte Bild (y) 69 | 70 | #header bauen - Useragent 71 | headers = { 'User-Agent' : 'Tiles2BigMap' } 72 | 73 | #url bauen 74 | tileurl = getTileURL(tileserver,x,y,zoom)# 'http://tile.openstreetmap.org/'+str(zoom)+'/'+str(x)+'/'+str(y)+'.png' 75 | 76 | #request 77 | req = urllib2.Request(tileurl, None, headers) 78 | 79 | u = urllib2.urlopen(req) 80 | #Tile speichern 81 | localFile = open('./tmp/'+str(zoom)+'-'+str(x)+'-'+str(y)+'.png', 'w') 82 | localFile.write(u.read()) 83 | localFile.close() 84 | 85 | 86 | #in Bild einfuegen 87 | b = Image.open('./tmp/'+str(zoom)+'-'+str(x)+'-'+str(y)+'.png') 88 | 89 | mainimage.paste(b,(xanz*scale,yanz*scale,(xanz+1)*scale,(yanz+1)*scale)) 90 | 91 | 92 | #output 93 | 94 | try: 95 | if(len(optionen.output)>0): 96 | outputfilename = optionen.output 97 | else: 98 | outputfilename = "./karte.png" 99 | except: 100 | outputfilename = "./karte.png" 101 | 102 | mainimage.save(outputfilename,"PNG") 103 | mainimage.show() 104 | 105 | 106 | 107 | --------------------------------------------------------------------------------