-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtile.py
35 lines (25 loc) · 961 Bytes
/
tile.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
# -*- coding: utf-8 -*-
import os
import re
from PIL import Image
from settings import TILE_SERVER, TILE_FOLDER, LATEST_PREC_FOLDER
def stitch_tiles(folder=LATEST_PREC_FOLDER):
"""
The images as downloaded from OpenStreetMap and OpenWeatherMap come in
256 pixel tiles. This function pastes these back together into a full
4096 × 4096 image of the earth.
"""
if not folder:
print "No folder found."
return False
ZOOM_LEVEL = z = 4
TILE_SIZE = 256
full_img = Image.new("RGBA", (z ** 2 * TILE_SIZE, z ** 2 * TILE_SIZE))
for x in range(z ** 2):
for y in range(z ** 2):
img_path = os.path.join(TILE_FOLDER, folder, str(z), str(x), '%s.png' % y)
img = Image.open(img_path)
full_img.paste(img, (x * TILE_SIZE, y * TILE_SIZE))
full_img.save(os.path.join(TILE_FOLDER, "%s.png" % folder))
if __name__ == '__main__':
stitch_tiles()