-
Notifications
You must be signed in to change notification settings - Fork 7
/
mapisart-compose.py
49 lines (37 loc) · 1.73 KB
/
mapisart-compose.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
36
37
38
39
40
41
42
43
44
45
46
47
48
import ModestMaps
import TileStache
from PIL import Image
from optparse import OptionParser
parser = OptionParser(usage="""tilestache-compose.py [options] file
tilestache-compose.py -c config.json -l layer-name -e 36.9 -123.5 38.9 -121.2 -z 9 out.jpg""")
defaults = dict(center=(37.8044, -122.2712), zoom=14, dimensions=(900, 600), verbose=True)
parser.set_defaults(**defaults)
parser.add_option('-c', '--config', dest='config',
help='Path to configuration file.')
parser.add_option('-e', '--extent', dest='extent', nargs=4,
help='Geographic extent of map. Two lat, lon pairs', type='float',
action='store')
parser.add_option('-z', '--zoom', dest='zoom',
help='Zoom level. Default %(zoom)d.' % defaults, type='int',
action='store')
parser.add_option('-d', '--dimensions', dest='dimensions', nargs=2,
help='Pixel width, height of output image. Default %d, %d.' % defaults['dimensions'], type='int',
action='store')
if __name__ == '__main__':
(options, args) = parser.parse_args()
tiledim = 256
width, height = options.dimensions
zoom = options.zoom
config = TileStache.parseConfigfile(options.config)
provider = config.layers['watercolor'].provider
proj = config.layers['watercolor'].projection
srs = proj.srs
extent = options.extent
bl = proj.locationProj(ModestMaps.Geo.Location(extent[0],extent[1]))
ur = proj.locationProj(ModestMaps.Geo.Location(extent[2],extent[3]))
xmin, ymin = bl.x, bl.y
xmax, ymax = ur.x, ur.y
print 'starting', args[0]
im = provider.renderArea(width, height, srs, xmin, ymin, xmax, ymax, zoom)
print 'render finished'
im.save(args[0])