/[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 413 by jonathan, Wed Feb 19 16:52:04 2003 UTC revision 465 by jonathan, Wed Mar 5 18:18:06 2003 UTC
# Line 28  from Thuban.Model.layer import Layer Line 28  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, \  from Thuban.Model.classification import Classification, \
31      ClassDataDefault, ClassDataPoint, ClassDataRange, ClassDataMap      ClassGroupDefault, ClassGroupSingleton, ClassGroupRange, ClassGroupMap, \
32        ClassGroupProperties
33    
34    
35  def parse_color(color):  def parse_color(color):
# Line 150  class ProcessSession(xml.sax.handler.Con Line 151  class ProcessSession(xml.sax.handler.Con
151          stroke = parse_color(attrs.get((None, 'stroke'), "#000000"))          stroke = parse_color(attrs.get((None, 'stroke'), "#000000"))
152          stroke_width = int(attrs.get((None, 'stroke_width'), "1"))          stroke_width = int(attrs.get((None, 'stroke_width'), "1"))
153          self.aLayer = layer_class(title, filename, fill = fill,          self.aLayer = layer_class(title, filename, fill = fill,
154                                    stroke = stroke, stroke_width = stroke_width)                                    stroke = stroke, lineWidth = stroke_width)
155      start_dispatcher['layer'] = "start_layer"      start_dispatcher['layer'] = "start_layer"
156    
157      def end_layer(self, name, qname):      def end_layer(self, name, qname):
# Line 158  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.GetClassification().SetField(          field = attrs.get((None, 'field'), None)
163              attrs.get((None, 'field'), None))  
164            fieldType = attrs.get((None, 'field_type'), None)
165            dbFieldType = self.aLayer.GetFieldType(field)
166    
167            if fieldType != dbFieldType:
168                raise ValueError(_("xml field type differs from database!"))
169    
170            # setup conversion routines depending on the kind of data
171            # we will be seeing later on
172            if fieldType == FIELDTYPE_STRING:
173                self.conv = str
174            elif fieldType == FIELDTYPE_INT:
175                self.conv = lambda p: int(float(p))
176            elif fieldType == FIELDTYPE_DOUBLE:
177                self.conv = float
178    
179            self.aLayer.GetClassification().SetField(field)
180    
181      start_dispatcher['classification'] = "start_classification"      start_dispatcher['classification'] = "start_classification"
182    
183      def end_classification(self, name, qname):      def end_classification(self, name, qname):
# Line 167  class ProcessSession(xml.sax.handler.Con Line 185  class ProcessSession(xml.sax.handler.Con
185      end_dispatcher['classification'] = "end_classification"      end_dispatcher['classification'] = "end_classification"
186    
187      def start_clnull(self, name, qname, attrs):      def start_clnull(self, name, qname, attrs):
188          self.cl_data = ClassDataDefault()          self.cl_group = ClassGroupDefault()
189          self.cl_data.SetLabel(attrs.get((None, 'label'), ""))          self.cl_group.SetLabel(attrs.get((None, 'label'), ""))
190            self.cl_prop = ClassGroupProperties()
191      start_dispatcher['clnull'] = "start_clnull"      start_dispatcher['clnull'] = "start_clnull"
192    
193      def end_clnull(self, name, qname):      def end_clnull(self, name, qname):
194          self.aLayer.GetClassification().SetDefaultData(self.cl_data)          self.cl_group.SetProperties(self.cl_prop)
195          del self.cl_data          self.aLayer.GetClassification().SetDefaultGroup(self.cl_group)
196            del self.cl_group, self.cl_prop
197      end_dispatcher['clnull'] = "end_clnull"      end_dispatcher['clnull'] = "end_clnull"
198    
199      def start_clpoint(self, name, qname, attrs):      def start_clpoint(self, name, qname, attrs):
200          attrib_value = attrs.get((None, 'value'), "0")          attrib_value = attrs.get((None, 'value'), "0")
201    
202          try:          #try:
203              value  = Str2Num(attrib_value)              #value  = Str2Num(attrib_value)
204          except:          #except:
205              value  = attrib_value              #value  = attrib_value
206    
207          self.cl_data = ClassDataPoint(value)          value = self.conv(attrib_value)
208          self.cl_data.SetLabel(attrs.get((None, 'label'), ""))  
209            self.cl_group = ClassGroupSingleton(value)
210            self.cl_group.SetLabel(attrs.get((None, 'label'), ""))
211            self.cl_prop = ClassGroupProperties()
212    
213      start_dispatcher['clpoint'] = "start_clpoint"      start_dispatcher['clpoint'] = "start_clpoint"
214    
215      def end_clpoint(self, name, qname):      def end_clpoint(self, name, qname):
216          self.aLayer.GetClassification().AddClassData(self.cl_data)          self.cl_group.SetProperties(self.cl_prop)
217          del self.cl_data          self.aLayer.GetClassification().AddGroup(self.cl_group)
218            del self.cl_group, self.cl_prop
219      end_dispatcher['clpoint'] = "end_clpoint"      end_dispatcher['clpoint'] = "end_clpoint"
220    
221      def start_clrange(self, name, qname, attrs):      def start_clrange(self, name, qname, attrs):
222    
223          try:          try:
224              min = Str2Num(attrs.get((None, 'min'), "0"))              min = self.conv(attrs.get((None, 'min'), "0"))
225              max = Str2Num(attrs.get((None, 'max'), "0"))              max = self.conv(attrs.get((None, 'max'), "0"))
226                #min = Str2Num(attrs.get((None, 'min'), "0"))
227                #max = Str2Num(attrs.get((None, 'max'), "0"))
228          except ValueError:          except ValueError:
229              raise ValueError(_("Classification range is not a number!"))              raise ValueError(_("Classification range is not a number!"))
230    
231          self.cl_data = ClassDataRange(min, max)          self.cl_group = ClassGroupRange(min, max)
232          self.cl_data.SetLabel(attrs.get((None, 'label'), ""))          self.cl_group.SetLabel(attrs.get((None, 'label'), ""))
233            self.cl_prop = ClassGroupProperties()
234    
235      start_dispatcher['clrange'] = "start_clrange"      start_dispatcher['clrange'] = "start_clrange"
236    
237      def end_clrange(self, name, qname):      def end_clrange(self, name, qname):
238          self.aLayer.GetClassification().AddClassData(self.cl_data)          self.cl_group.SetProperties(self.cl_prop)
239          del self.cl_data          self.aLayer.GetClassification().AddGroup(self.cl_group)
240            del self.cl_group, self.cl_prop
241      end_dispatcher['clrange'] = "end_clrange"      end_dispatcher['clrange'] = "end_clrange"
242    
243      def start_cldata(self, name, qname, attrs):      def start_cldata(self, name, qname, attrs):
244          self.cl_data.SetStroke(parse_color(attrs.get((None, 'stroke'), "None")))          self.cl_prop.SetLineColor(
245          self.cl_data.SetStrokeWidth(              parse_color(attrs.get((None, 'stroke'), "None")))
246            self.cl_prop.SetLineWidth(
247              int(attrs.get((None, 'stroke_width'), "0")))              int(attrs.get((None, 'stroke_width'), "0")))
248          self.cl_data.SetFill(parse_color(attrs.get((None, 'fill'), "None")))          self.cl_prop.SetFill(parse_color(attrs.get((None, 'fill'), "None")))
249      start_dispatcher['cldata'] = "start_cldata"      start_dispatcher['cldata'] = "start_cldata"
250    
251      def end_cldata(self, name, qname):      def end_cldata(self, name, qname):

Legend:
Removed from v.413  
changed lines
  Added in v.465

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26