Example #1
0
#!/usr/bin/env python
import sys
import os
from render_tile import ImageProvider
from ast import literal_eval as make_tuple

if __name__ == "__main__":

    mapfile = os.environ['MAPNIK_MAP_FILE']
    tile_file = os.environ['MAPNIK_TILE_FILE']
    bbox = make_tuple(os.environ['MAPNIK_BBOX'])

    renderer = ImageProvider(mapfile)
    img = renderer.render_bounding(bbox)
    img.save(tile_file, 'png256')
Example #2
0
#!/usr/bin/env python
import sys
import json
from render_tile import ImageProvider
import struct

while 1:
    line = sys.stdin.readline()
    if not line:
        break
    try:
        env = json.loads(line)
        renderer = ImageProvider(str(env.get('mapnikXml')))
        imgString = renderer.render_tile(env.get('x'), env.get('y'), env.get('z'), env.get('utfGrid'))
        imgStringByteArray = bytearray(imgString)
        imgStringLen = len(imgStringByteArray)
        # for debugging
        # sys.stderr.write('len: ' + str(imgStringLen) + '\n')
        # sys.stderr.flush()

        sys.stdout.write(struct.pack('!i', imgStringLen))
        sys.stdout.write(imgStringByteArray)
        sys.stdout.flush()
    except Exception as e:
        sys.stderr.write(str(e) + '\n')
        sys.stderr.flush()
        # write 0 so java nows there was an error
        sys.stdout.write(struct.pack('!i', 0))
        sys.stdout.flush()