source: subversion/applications/rendering/mapnik/generate_image.py @ 4139

Last change on this file since 4139 was 3244, checked in by jonb, 13 years ago

generate_image.py: Script for generating a large mapnik image

  • Property svn:executable set to *
File size: 1.1 KB
Line 
1#!/usr/bin/python
2#
3# Generates a single large PNG image for a UK bounding box
4# Tweak the lat/lon bounding box (ll) and image dimensions
5# to get an image of arbitrary size.
6#
7# To use this script you must first have installed mapnik
8# and imported a planet file into a Postgres DB using
9# osm2pgsql.
10#
11# Note that mapnik renders data differently depending on
12# the size of image. More detail appears as the image size
13# increases but note that the text is rendered at a constant
14# pixel size so will appear smaller on a large image.
15
16from mapnik import *
17
18if __name__ == "__main__":
19    mapfile = "osm.xml"
20    tile_uri = "image.png"
21    ll = (-6.5,  49.5,   2.1,59)
22    z = 10
23    imgx = 500 * z
24    imgy = 1000 * z
25
26    m = Map(imgx,imgy)
27    load_map(m,mapfile)
28    prj = Projection("+proj=merc +datum=WGS84")
29    c0 = prj.forward(Coord(ll[0],ll[1]))
30    c1 = prj.forward(Coord(ll[2],ll[3]))
31    bbox = Envelope(c0.x,c0.y,c1.x,c1.y)
32    m.zoom_to_box(bbox)
33    im = Image(imgx,imgy)
34    render(m, im)
35    view = im.view(0,0,imgx,imgy) # x,y,width,height
36    save_to_file(tile_uri,'png',view)
Note: See TracBrowser for help on using the repository browser.