/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/load.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/Model/load.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 267 by bh, Thu Aug 22 10:25:30 2002 UTC revision 390 by jonathan, Mon Feb 10 15:25:49 2003 UTC
# Line 18  import xml.sax Line 18  import xml.sax
18  import xml.sax.handler  import xml.sax.handler
19  from xml.sax import make_parser, ErrorHandler  from xml.sax import make_parser, ErrorHandler
20    
21    from Thuban import _
22  from Thuban.Model.session import Session  from Thuban.Model.session import Session
23  from Thuban.Model.map import Map  from Thuban.Model.map import Map
24  from Thuban.Model.layer import Layer  from Thuban.Model.layer import Layer
25  from Thuban.Model.color import Color  from Thuban.Model.color import Color
26  from Thuban.Model.proj import Projection  from Thuban.Model.proj import Projection
27    from Thuban.Model.classification import Classification, ClassData
28    
29    
30  def parse_color(color):  def parse_color(color):
# Line 41  def parse_color(color): Line 43  def parse_color(color):
43              b = string.atoi(color[5:7], 16) / 255.0              b = string.atoi(color[5:7], 16) / 255.0
44              result = Color(r, g, b)              result = Color(r, g, b)
45          else:          else:
46              raise ValueError("Invalid hexadecimal color specification %s"              raise ValueError(_("Invalid hexadecimal color specification %s")
47                               % color)                               % color)
48      else:      else:
49          raise ValueError("Invalid color specification %s" % color)          raise ValueError(_("Invalid color specification %s") % color)
50      return result      return result
51    
52    
53  class ProcessSession(xml.sax.handler.ContentHandler):  class ProcessSession(xml.sax.handler.ContentHandler):
54    
55      # Dictionary mapping element names (or (URI, element name) pairs for      # Dictionary mapping element names (or (URI, element name) pairs for
56      # documents using amespaces) to method names. The methods should      # documents using namespaces) to method names. The methods should
57      # accept the same parameters as the startElement (or startElementNS)      # accept the same parameters as the startElement (or startElementNS)
58      # methods. The start_dispatcher is used by the default startElement      # methods. The start_dispatcher is used by the default startElement
59      # and startElementNS methods to call a method for the open tag of an      # and startElementNS methods to call a method for the open tag of an
# Line 151  class ProcessSession(xml.sax.handler.Con Line 153  class ProcessSession(xml.sax.handler.Con
153          self.aMap.AddLayer(self.aLayer)          self.aMap.AddLayer(self.aLayer)
154      end_dispatcher['layer'] = "end_layer"      end_dispatcher['layer'] = "end_layer"
155    
156        def start_classification(self, name, qname, attrs):
157            self.aLayer.classification.SetField(attrs.get((None, 'field'), None))
158        start_dispatcher['classification'] = "start_classification"
159    
160        def end_classification(self, name, qname):
161            pass
162        end_dispatcher['classification'] = "end_classification"
163    
164        def start_clnull(self, name, qname, attrs):
165            self.cl_data = ClassData()
166        start_dispatcher['clnull'] = "start_clnull"
167    
168        def end_clnull(self, name, qname):
169            self.aLayer.classification.SetDefaultData(self.cl_data)
170            del self.cl_data
171        end_dispatcher['clnull'] = "end_clnull"
172    
173        def start_clpoint(self, name, qname, attrs):
174            attrib_value = attrs.get((None, 'value'), "0")
175    
176            try:
177                self.cl_value  = int(attrib_value)
178            except:
179                self.cl_value  = attrib_value
180    
181            self.cl_data = ClassData()
182        start_dispatcher['clpoint'] = "start_clpoint"
183    
184        def end_clpoint(self, name, qname):
185            self.aLayer.classification.AddPoint(self.cl_value, self.cl_data)
186            del self.cl_value, self.cl_data
187        end_dispatcher['clpoint'] = "end_clpoint"
188    
189        def start_clrange(self, name, qname, attrs):
190    
191            try:
192                self.cl_low = int(attrs.get((None, 'low'), "0"))
193                self.cl_high = int(attrs.get((None, 'high'), "0"))
194            except ValueError:
195                raise ValueError(_("Classification range is not a number!"))
196    
197            self.cl_data = ClassData()
198        start_dispatcher['clrange'] = "start_clrange"
199    
200        def end_clrange(self, name, qname):
201            self.aLayer.classification.AddRange(
202                self.cl_low, self.cl_high, self.cl_data)
203            del self.cl_low, self.cl_high, self.cl_data
204        end_dispatcher['clrange'] = "end_clrange"
205    
206        def start_cldata(self, name, qname, attrs):
207            self.cl_data.SetStroke(parse_color(attrs.get((None, 'stroke'), "None")))
208            self.cl_data.SetStrokeWidth(
209                int(attrs.get((None, 'stroke_width'), "0")))
210            self.cl_data.SetFill(parse_color(attrs.get((None, 'fill'), "None")))
211        start_dispatcher['cldata'] = "start_cldata"
212    
213        def end_cldata(self, name, qname):
214            pass
215        end_dispatcher['cldata'] = "end_cldata"
216    
217      def start_table(self, name, qname, attrs):      def start_table(self, name, qname, attrs):
218          print "table title: %s" % attrs.get('title', None)          print "table title: %s" % attrs.get('title', None)
219      start_dispatcher['table'] = "start_table"      start_dispatcher['table'] = "start_table"

Legend:
Removed from v.267  
changed lines
  Added in v.390

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26