/[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 390 by jonathan, Mon Feb 10 15:25:49 2003 UTC revision 439 by jonathan, Thu Feb 27 15:54:05 2003 UTC
# Line 2  Line 2 
2  # Authors:  # Authors:
3  # Jan-Oliver Wagner <[email protected]>  # Jan-Oliver Wagner <[email protected]>
4  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
5    # Jonathan Coles <[email protected]>
6  #  #
7  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
8  # Read the file COPYING coming with GRASS for details.  # Read the file COPYING coming with GRASS for details.
# Line 19  import xml.sax.handler Line 20  import xml.sax.handler
20  from xml.sax import make_parser, ErrorHandler  from xml.sax import make_parser, ErrorHandler
21    
22  from Thuban import _  from Thuban import _
23    from Thuban.common import *
24    
25  from Thuban.Model.session import Session  from Thuban.Model.session import Session
26  from Thuban.Model.map import Map  from Thuban.Model.map import Map
27  from Thuban.Model.layer import Layer  from Thuban.Model.layer import Layer
28  from Thuban.Model.color import Color  from Thuban.Model.color import Color
29  from Thuban.Model.proj import Projection  from Thuban.Model.proj import Projection
30  from Thuban.Model.classification import Classification, ClassData  from Thuban.Model.classification import Classification, \
31        ClassGroupDefault, ClassGroupSingleton, ClassGroupRange, ClassGroupMap, \
32        ClassGroupProperties
33    
34    
35  def parse_color(color):  def parse_color(color):
# Line 35  def parse_color(color): Line 40  def parse_color(color):
40      """      """
41      color = string.strip(color)      color = string.strip(color)
42      if color == "None":      if color == "None":
43          result = None          result = Color.None
44      elif color[0] == '#':      elif color[0] == '#':
45          if len(color) == 7:          if len(color) == 7:
46              r = string.atoi(color[1:3], 16) / 255.0              r = string.atoi(color[1:3], 16) / 255.0
# Line 154  class ProcessSession(xml.sax.handler.Con Line 159  class ProcessSession(xml.sax.handler.Con
159      end_dispatcher['layer'] = "end_layer"      end_dispatcher['layer'] = "end_layer"
160    
161      def start_classification(self, name, qname, attrs):      def start_classification(self, name, qname, attrs):
162          self.aLayer.classification.SetField(attrs.get((None, 'field'), None))          self.aLayer.GetClassification().SetField(
163                attrs.get((None, 'field'), None))
164      start_dispatcher['classification'] = "start_classification"      start_dispatcher['classification'] = "start_classification"
165    
166      def end_classification(self, name, qname):      def end_classification(self, name, qname):
# Line 162  class ProcessSession(xml.sax.handler.Con Line 168  class ProcessSession(xml.sax.handler.Con
168      end_dispatcher['classification'] = "end_classification"      end_dispatcher['classification'] = "end_classification"
169    
170      def start_clnull(self, name, qname, attrs):      def start_clnull(self, name, qname, attrs):
171          self.cl_data = ClassData()          self.cl_group = ClassGroupDefault()
172            self.cl_group.SetLabel(attrs.get((None, 'label'), ""))
173            self.cl_prop = ClassGroupProperties()
174      start_dispatcher['clnull'] = "start_clnull"      start_dispatcher['clnull'] = "start_clnull"
175    
176      def end_clnull(self, name, qname):      def end_clnull(self, name, qname):
177          self.aLayer.classification.SetDefaultData(self.cl_data)          self.cl_group.SetProperties(self.cl_prop)
178          del self.cl_data          self.aLayer.GetClassification().SetDefaultGroup(self.cl_group)
179            del self.cl_group, self.cl_prop
180      end_dispatcher['clnull'] = "end_clnull"      end_dispatcher['clnull'] = "end_clnull"
181    
182      def start_clpoint(self, name, qname, attrs):      def start_clpoint(self, name, qname, attrs):
183          attrib_value = attrs.get((None, 'value'), "0")          attrib_value = attrs.get((None, 'value'), "0")
184    
185          try:          try:
186              self.cl_value  = int(attrib_value)              value  = Str2Num(attrib_value)
187          except:          except:
188              self.cl_value  = attrib_value              value  = attrib_value
189    
190            self.cl_group = ClassGroupSingleton(value)
191            self.cl_group.SetLabel(attrs.get((None, 'label'), ""))
192            self.cl_prop = ClassGroupProperties()
193    
         self.cl_data = ClassData()  
194      start_dispatcher['clpoint'] = "start_clpoint"      start_dispatcher['clpoint'] = "start_clpoint"
195    
196      def end_clpoint(self, name, qname):      def end_clpoint(self, name, qname):
197          self.aLayer.classification.AddPoint(self.cl_value, self.cl_data)          self.cl_group.SetProperties(self.cl_prop)
198          del self.cl_value, self.cl_data          self.aLayer.GetClassification().AddGroup(self.cl_group)
199            del self.cl_group, self.cl_prop
200      end_dispatcher['clpoint'] = "end_clpoint"      end_dispatcher['clpoint'] = "end_clpoint"
201    
202      def start_clrange(self, name, qname, attrs):      def start_clrange(self, name, qname, attrs):
203    
204          try:          try:
205              self.cl_low = int(attrs.get((None, 'low'), "0"))              min = Str2Num(attrs.get((None, 'min'), "0"))
206              self.cl_high = int(attrs.get((None, 'high'), "0"))              max = Str2Num(attrs.get((None, 'max'), "0"))
207          except ValueError:          except ValueError:
208              raise ValueError(_("Classification range is not a number!"))              raise ValueError(_("Classification range is not a number!"))
209    
210          self.cl_data = ClassData()          self.cl_group = ClassGroupRange(min, max)
211            self.cl_group.SetLabel(attrs.get((None, 'label'), ""))
212            self.cl_prop = ClassGroupProperties()
213    
214      start_dispatcher['clrange'] = "start_clrange"      start_dispatcher['clrange'] = "start_clrange"
215    
216      def end_clrange(self, name, qname):      def end_clrange(self, name, qname):
217          self.aLayer.classification.AddRange(          self.cl_group.SetProperties(self.cl_prop)
218              self.cl_low, self.cl_high, self.cl_data)          self.aLayer.GetClassification().AddGroup(self.cl_group)
219          del self.cl_low, self.cl_high, self.cl_data          del self.cl_group, self.cl_prop
220      end_dispatcher['clrange'] = "end_clrange"      end_dispatcher['clrange'] = "end_clrange"
221    
222      def start_cldata(self, name, qname, attrs):      def start_cldata(self, name, qname, attrs):
223          self.cl_data.SetStroke(parse_color(attrs.get((None, 'stroke'), "None")))          self.cl_prop.SetStroke(parse_color(attrs.get((None, 'stroke'), "None")))
224          self.cl_data.SetStrokeWidth(          self.cl_prop.SetStrokeWidth(
225              int(attrs.get((None, 'stroke_width'), "0")))              int(attrs.get((None, 'stroke_width'), "0")))
226          self.cl_data.SetFill(parse_color(attrs.get((None, 'fill'), "None")))          self.cl_prop.SetFill(parse_color(attrs.get((None, 'fill'), "None")))
227      start_dispatcher['cldata'] = "start_cldata"      start_dispatcher['cldata'] = "start_cldata"
228    
229      def end_cldata(self, name, qname):      def end_cldata(self, name, qname):

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26