source: src/gheat/__/bin/gen-tile.py@ 8990

Last change on this file since 8990 was 8853, checked in by dennisw, 14 years ago

stageplan_0.1 - toegevoegd
gheat - sourcecode toegevoegd
website_ontwerp - map aangepast, komt nu beter overeen met idee dat ik heb

File size: 2.0 KB
Line 
1#!/usr/bin/env python
2# generate tiles
3
4"""Generate gheat tiles.
5"""
6import math
7import os
8import sys
9from os.path import join
10
11import aspen
12root = aspen.find_root()
13aspen.configure(['--root', root])
14
15from gmerc import ll2px
16from gheat import pil_ as backend
17
18
19color_schemes = dict() # this is used below
20_color_schemes_dir = os.path.join(aspen.paths.__, 'etc', 'color-schemes')
21for fname in os.listdir(_color_schemes_dir):
22 if not fname.endswith('.png'):
23 continue
24 name = os.path.splitext(fname)[0]
25 fspath = os.path.join(_color_schemes_dir, fname)
26 color_schemes[name] = backend.ColorScheme(name, fspath)
27
28
29def load_dots(backend):
30 """Given a backend module, return a mapping of zoom level to Dot object.
31 """
32 return dict([(zoom, backend.Dot(zoom)) for zoom in range(16)])
33dots = load_dots(backend) # factored for easier use from scripts
34
35
36for zoom in [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]: # generate for zoomlevels
37 width, height = ll2px(-90, 180, zoom)
38 numcols = int(math.ceil(width / 256.0))
39 numrows = int(math.ceil(height / 256.0))
40 cs_name = 'classic'
41 color_scheme = color_schemes[cs_name]
42 for x in range(numcols):
43 for y in range(numrows):
44 fspath = join( aspen.paths.root
45 , cs_name
46 , str(zoom)
47 , "%d,%d" % (x, y)
48 ) + '.png'
49 tile = backend.Tile(color_scheme, dots, zoom, x, y, fspath)
50 sys.stdout.write('tile %s\n' % fspath); sys.stdout.flush()
51 if tile.is_empty():
52 sys.stdout.flush()
53 elif tile.is_stale():
54 sys.stdout.write('rebuilding tile %s\n' % fspath)
55 sys.stdout.flush()
56 tile.rebuild()
57 tile.save()
58 else:
59 sys.stdout.write('skipping cached tile %s\n' % fspath)
60 sys.stdout.flush()
Note: See TracBrowser for help on using the repository browser.