Package sabx10 :: Package osm :: Module styles
[hide private]
[frames] | no frames]

Source Code for Module sabx10.osm.styles

 1  ############################################################################### 
 2  # 
 3  # sabx10 - an SABX file manipulation library 
 4  # Copyright (C) 2009, 2010 Jay Farrimond (jay@sabikerides.com) 
 5  # 
 6  # This file is part of sabx10. 
 7  # 
 8  # sabx10 is free software: you can redistribute it and/or modify it under the 
 9  # terms of the GNU General Public License as published by the Free Software 
10  # Foundation, either version 3 of the License, or (at your option) any later 
11  # version. 
12  # 
13  # sabx10 is distributed in the hope that it will be useful, but WITHOUT ANY 
14  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 
15  # A PARTICULAR PURPOSE.  See the GNU General Public License for more details. 
16  # 
17  # You should have received a copy of the GNU General Public License along with 
18  # sabx10.  If not, see <http://www.gnu.org/licenses/>. 
19  # 
20  ############################################################################### 
21  """ 
22  Provide the tools to generate style sheets used by Mapnik for rendering maps. 
23  """ 
24  import os.path 
25   
26  from sabx10.templating import TemplateProcessor, SabxProcessor, \ 
27      strip_end_slash 
28   
29  from consts import PIX_SCALE_FACTOR 
30   
31 -class StyleProcessor(SabxProcessor):
32 """ 33 Handle the processing of a style template. This will generate the style 34 sheet necessary for Mapnik to know how to generate a map. 35 """
36 - def __init__(self, template_file=None, man=None):
37 """ 38 Add support for an OSM data file and a logo directory. 39 40 @param template_file: name of template file to use 41 @type template_file: C{string} 42 @param man: text for man page 43 @type man: C{string} 44 """ 45 SabxProcessor.__init__(self, template_file, man) 46 47 self.parser.add_option("-d", "--datafile", dest="data_file", 48 help="osm data FILE name", 49 metavar="FILE") 50 self.parser.add_option("-l", "--logodir", dest="logo_dir", 51 help="osm logo directory", 52 metavar="LOGO") 53 54 self.template_data['PIX_SCALE_FACTOR'] = PIX_SCALE_FACTOR
55
56 - def process_options(self):
57 """ 58 Process the OSM data file file and logo directory. 59 """ 60 SabxProcessor.process_options(self) 61 62 base_path, base_file = os.path.split(self.options.out_file) 63 self.template_data['osm_data'] = \ 64 os.path.abspath(os.path.join(base_path, "map.osm")) 65 self.template_data['logo_dir'] = strip_end_slash(self.options.logo_dir)
66
67 - def process_template(self):
68 """ 69 Generate a template file for each ride in the rideset. 70 """ 71 out_base = self.options.out_file 72 for index in range(len(self.template_data['ride_list'])): 73 self.template_data['route_index'] = index 74 self.options.out_file = "%s_%s.xml" % (out_base, index) 75 TemplateProcessor.process_template(self)
76