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

Last change on this file since 19869 was 19869, checked in by ldp, 10 years ago

Fix last commit. Mapnik trunk is currently 800.

  • Property svn:executable set to *
File size: 1.5 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 *
17import sys, os
18
19if __name__ == "__main__":
20    try:
21        mapfile = os.environ['MAPNIK_MAP_FILE']
22    except KeyError:
23        mapfile = "osm.xml"
24    map_uri = "image.png"
25
26    #---------------------------------------------------
27    #  Change this to the bounding box you want
28    #
29    ll = (-6.5, 49.5, 2.1, 59)
30    #---------------------------------------------------
31
32    z = 10
33    imgx = 500 * z
34    imgy = 1000 * z
35
36    m = Map(imgx,imgy)
37    load_map(m,mapfile)
38    prj = Projection("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over")
39    c0 = prj.forward(Coord(ll[0],ll[1]))
40    c1 = prj.forward(Coord(ll[2],ll[3]))
41    if hasattr(mapnik,'mapnik_version') and mapnik.mapnik_version() >= 800:
42        bbox = Box2d(c0.x,c0.y,c1.x,c1.y)
43    else:
44        bbox = Envelope(c0.x,c0.y,c1.x,c1.y)
45    m.zoom_to_box(bbox)
46    im = Image(imgx,imgy)
47    render(m, im)
48    view = im.view(0,0,imgx,imgy) # x,y,width,height
49    view.save(map_uri,'png')
Note: See TracBrowser for help on using the repository browser.