/[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 2446 by frank, Mon Dec 13 11:52:34 2004 UTC revision 2688 by frank, Fri Jun 30 12:27:20 2006 UTC
# Line 1  Line 1 
1  # Copyright (C) 2001, 2002, 2003, 2004 by Intevation GmbH  # Copyright (C) 2001, 2002, 2003, 2004, 2005 by Intevation GmbH
2  # Authors:  # Authors:
3  # Jan-Oliver Wagner <[email protected]>  # Jan-Oliver Wagner <[email protected]>
4  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
# Line 33  from Thuban.Model.layer import Layer, Ra Line 33  from Thuban.Model.layer import Layer, Ra
33  from Thuban.Model.proj import Projection  from Thuban.Model.proj import Projection
34  from Thuban.Model.range import Range  from Thuban.Model.range import Range
35  from Thuban.Model.classification import Classification, \  from Thuban.Model.classification import Classification, \
36      ClassGroupDefault, ClassGroupSingleton, ClassGroupRange, ClassGroupMap, \      ClassGroupDefault, ClassGroupSingleton, ClassGroupRange, \
37        ClassGroupPattern, ClassGroupMap, \
38      ClassGroupProperties      ClassGroupProperties
39  from Thuban.Model.data import DerivedShapeStore, ShapefileStore  from Thuban.Model.data import DerivedShapeStore, ShapefileStore
40  from Thuban.Model.table import DBFTable  from Thuban.Model.table import DBFTable
# Line 136  class SessionLoader(XMLReader): Line 137  class SessionLoader(XMLReader):
137              'clnull'        : ("start_clnull",         "end_clnull"),              'clnull'        : ("start_clnull",         "end_clnull"),
138              'clpoint'       : ("start_clpoint",        "end_clpoint"),              'clpoint'       : ("start_clpoint",        "end_clpoint"),
139              'clrange'       : ("start_clrange",        "end_clrange"),              'clrange'       : ("start_clrange",        "end_clrange"),
140                'clpattern'     : ("start_clpattern",      "end_clpattern"),
141              'cldata'        : ("start_cldata",         "end_cldata"),              'cldata'        : ("start_cldata",         "end_cldata"),
142              'table'         : ("start_table",          "end_table"),              'table'         : ("start_table",          "end_table"),
143              'labellayer'    : ("start_labellayer",     None),              'labellayer'    : ("start_labellayer",     None),
# Line 248  class SessionLoader(XMLReader): Line 250  class SessionLoader(XMLReader):
250                                      % (element, d.name))                                      % (element, d.name))
251              elif d.conversion == "filename":              elif d.conversion == "filename":
252                  value = os.path.abspath(os.path.join(self.GetDirectory(),                  value = os.path.abspath(os.path.join(self.GetDirectory(),
253                                                       value))                                                       self.encode(value)))
254              elif d.conversion == "ascii":              elif d.conversion == "ascii":
255                  value = value.encode("ascii")                  value = value.encode("ascii")
256              elif d.conversion:              elif d.conversion:
# Line 261  class SessionLoader(XMLReader): Line 263  class SessionLoader(XMLReader):
263          return normalized          return normalized
264    
265      def open_shapefile(self, filename):      def open_shapefile(self, filename):
266          """Open shapefile, eventually with alternative path."""          """Open shapefile, with alternative path handling.
267            
268               If a shapefile cannot be opened and an IOError is raised, check for
269               an alternative. This alternative can be specified interactively by
270               the user or taken from a list of (potential) locations, depending on
271               the callback implementation.
272                
273               The alternative is rechecked. If taken from a list the user
274               has to confirm the alternative.
275            """
276    
277            # Flag if the alternative path was specified interactively / from list.
278          from_list = 0          from_list = 0
279          while 1:          while 1:
280              try:              try:
281                  store = self.theSession.OpenShapefile(filename)                  store = self.theSession.OpenShapefile(filename)
282                  if from_list:                  if from_list:
283                      # The correct? path has been guessed from a list                      # A valid path has been guessed from a list
284                      # Let the user confirm - or select an alternative.                      # Let the user confirm - or select an alternative.
285                      filename, from_list = self.shapefile_callback(                      filename, from_list = self.shapefile_callback(
286                                              filename, "check")                                              filename, "check")
# Line 290  class SessionLoader(XMLReader): Line 303  class SessionLoader(XMLReader):
303                                              second_try = from_list)                                              second_try = from_list)
304                      if filename is None:                      if filename is None:
305                          raise LoadCancelled                          raise LoadCancelled
                     print filename  
306                  else:                  else:
307                      raise                      raise
308          return store          return store
# Line 498  class SessionLoader(XMLReader): Line 510  class SessionLoader(XMLReader):
510          filename = os.path.join(self.GetDirectory(), filename)          filename = os.path.join(self.GetDirectory(), filename)
511          filename = self.encode(filename)          filename = self.encode(filename)
512          visible  = self.encode(attrs.get((None, 'visible'), "true")) != "false"          visible  = self.encode(attrs.get((None, 'visible'), "true")) != "false"
513            opacity  = float(attrs.get((None, 'opacity'), "1"))
514            masktype = str(attrs.get((None, 'masktype'), "bit"))
515    
516          self.aLayer = layer_class(title, filename, visible = visible)          masktypes = {"none": layer_class.MASK_NONE,
517                         "bit":  layer_class.MASK_BIT,
518                         "alpha": layer_class.MASK_ALPHA}
519    
520            self.aLayer = layer_class(title, filename,
521                                      visible = visible,
522                                      opacity = opacity,
523                                      masktype = masktypes[masktype])
524    
525      def end_rasterlayer(self, name, qname):      def end_rasterlayer(self, name, qname):
526          self.aMap.AddLayer(self.aLayer)          self.aMap.AddLayer(self.aLayer)
527          self.aLayer = None          self.aLayer = None
528    
529      def start_classification(self, name, qname, attrs):      def start_classification(self, name, qname, attrs):
530            # field and field_type are optional because the classification
531            # can also be empty, ie. have only a default.
532          attrs = self.check_attrs(name, attrs,          attrs = self.check_attrs(name, attrs,
533                                   [AttrDesc("field", True),                                   [AttrDesc("field", False),
534                                    AttrDesc("field_type", True)])                                    AttrDesc("field_type", False)])
535    
536          field = attrs["field"]          field = attrs["field"]
537          fieldType = attrs["field_type"]          fieldType = attrs["field_type"]
538    
539            if field == "": return # no need to set classification column.
540    
541          dbFieldType = self.aLayer.GetFieldType(field)          dbFieldType = self.aLayer.GetFieldType(field)
542    
543          if fieldType != dbFieldType:          if fieldType != dbFieldType:
# Line 560  class SessionLoader(XMLReader): Line 586  class SessionLoader(XMLReader):
586          del self.cl_group, self.cl_prop          del self.cl_group, self.cl_prop
587    
588      def start_clrange(self, name, qname, attrs):      def start_clrange(self, name, qname, attrs):
589            attrs = self.check_attrs(name, attrs,
590                                     [AttrDesc("range", False, None),
591                                      AttrDesc("min", False, None),
592                                      AttrDesc("max", False, None)])
593    
594          range = attrs.get((None, 'range'), None)          range = attrs['range']
595          # for backward compatibility (min/max are not saved)          # for backward compatibility (min/max are not saved)
596          min   = attrs.get((None, 'min'), None)          min   = attrs['min']
597          max   = attrs.get((None, 'max'), None)          max   = attrs['max']
598    
599          try:          try:
600              if range is not None:              if range is not None:
# Line 587  class SessionLoader(XMLReader): Line 617  class SessionLoader(XMLReader):
617          self.aLayer.GetClassification().AppendGroup(self.cl_group)          self.aLayer.GetClassification().AppendGroup(self.cl_group)
618          del self.cl_group, self.cl_prop          del self.cl_group, self.cl_prop
619    
620    
621        def start_clpattern(self, name, qname, attrs):
622            pattern = attrs.get((None, 'pattern'), "")
623    
624            self.cl_group = ClassGroupPattern(self.encode(pattern))
625            self.cl_group.SetLabel(self.encode(attrs.get((None, 'label'), "")))
626            self.cl_prop = ClassGroupProperties()
627    
628        def end_clpattern(self, name, qname):
629            self.cl_group.SetProperties(self.cl_prop)
630            self.aLayer.GetClassification().AppendGroup(self.cl_group)
631            del self.cl_group, self.cl_prop
632    
633    
634      def start_cldata(self, name, qname, attrs):      def start_cldata(self, name, qname, attrs):
635          self.cl_prop.SetLineColor(          self.cl_prop.SetLineColor(
636              parse_color(attrs.get((None, 'stroke'), "None")))              parse_color(attrs.get((None, 'stroke'), "None")))

Legend:
Removed from v.2446  
changed lines
  Added in v.2688

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26