source: subversion/applications/rendering/pyrender/renderer_sample_cairo.py @ 8190

Last change on this file since 8190 was 8190, checked in by spaetz, 12 years ago

fix typo

File size: 3.3 KB
Line 
1#!/usr/bin/python
2#----------------------------------------------------------------------------
3# Sample rendering engine
4#
5# Copy and modify this file to create your own rendering engine
6# - please keep this file clean so it's easy to understand how to
7#   derive copies of it
8#
9# To serve tiles using your new rendering engine, change the line at
10# the top of server.py, from:
11#   import renderer_simple as RenderModule
12# to:
13#   import renderer_yourNewModule as RenderModule
14#
15# ..then run server.py and view it on http://localhost:1280/ as usual
16#----------------------------------------------------------------------------
17# Copyright 2008, authors:
18# * Sebastian Spaeth
19# * Oliver White
20#
21# This program is free software: you can redistribute it and/or modify
22# it under the terms of the GNU General Public License as published by
23# the Free Software Foundation, either version 3 of the License, or
24# (at your option) any later version.
25#
26# This program is distributed in the hope that it will be useful,
27# but WITHOUT ANY WARRANTY; without even the implied warranty of
28# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29# GNU General Public License for more details.
30#
31# You should have received a copy of the GNU General Public License
32# along with this program.  If not, see <http://www.gnu.org/licenses/>.
33#---------------------------------------------------------------------------
34from render_cairo_base import OsmRenderBase
35
36class RenderClass(OsmRenderBase):
37 
38  # Specify the background for new tiles
39  def imageBackgroundColour(self):
40    return("white")
41   
42  # Draw a tile
43  def draw(self):
44    # Certain things have already been created for you at this point:
45    #
46    #  * self.osm contains the OpenStreetMap data for your tile
47    #     - w is a list of ways
48    #     - poi is a list of points-of-interest
49    #     - nodes is a hash of lat/long values for nodes
50    #
51    #  * self.ctx is a Cairo drawing context
52    #
53    #  * self.proj is a projection module, which you can pass lat/long
54    #    values and get image coordinates back, like:
55    #    (x,y) = self.proj.project(lat,lon)
56   
57    self.ctx.set_source_rgb(0, 0, 0)
58    # Example of parsing through all the ways
59    for w in self.osm.ways.values():
60      count = 0
61     
62      # way['n'] contains the list of its nodes
63      for n in w['n']: 
64       
65        # need to lookup that node's lat/long from the osm.nodes dictionary
66        (lat,lon) = self.osm.nodes[n]
67       
68        # project that into image coordinates
69        (x,y) = self.proj.project(lat,lon)
70       
71        # draw lines on the image
72        if(count == 0):
73          self.ctx.move_to(x, y)
74        else:
75          self.ctx.line_to(x, y)
76       
77        count = count + 1
78      self.ctx.stroke()
79   
80    # Similar code for points of interest
81    # (they have just one node, as ['id'])
82    if(0):
83      for poi in self.osm.poi:
84        n = poi['id']
85        (lat,lon) = self.osm.nodes[n]
86        (x,y) = self.proj.project(lat,lon)
87        # TODO: draw icon/text/whatever at x,y
88
89
90#-----------------------------------------------------------------
91# Test suite - call this file from the command-line to generate a
92# sample image
93if(__name__ == '__main__'):
94  a = RenderClass()
95  filename = "sample_"+__file__+".png"
96  a.RenderTile(17,65385,43658, filename)
97  print "------------------------------------"
98  print "Saved image to " + filename
Note: See TracBrowser for help on using the repository browser.