forked from perliedman/shadow-mapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender_background.py
More file actions
34 lines (27 loc) · 1.15 KB
/
render_background.py
File metadata and controls
34 lines (27 loc) · 1.15 KB
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
#!/usr/bin/env python
import mapnik
class MapRenderer():
def __init__(self, size, stylesheet):
self._map = mapnik.Map(size, size)
mapnik.load_map(self._map, stylesheet)
def render_to_file(self, xmin, ymin, xmax, ymax, path):
extent = mapnik.Box2d(xmin, ymin, xmax, ymax)
self._map.zoom_to_box(extent)
mapnik.render_to_file(self._map, path)
if __name__ == '__main__':
from map import Map
from heightmap import HeightMap
import os
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('heightmap', type=str, help='Heightmap file to create background for')
parser.add_argument('mapnik_xml', type=str, help='Mapnik XML file to render')
parser.add_argument('output_file', type=str, help='File to output result image to')
args = parser.parse_args()
with open(args.heightmap, 'rb') as f:
hm = Map.load(f)
cwd = os.getcwd()
os.chdir(os.path.dirname(args.mapnik_xml))
renderer = MapRenderer(hm.size, args.mapnik_xml)
xmin, ymin, xmax, ymax = hm.bounds
renderer.render_to_file(xmin, ymin, xmax, ymax, os.path.join(cwd, args.output_file))