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

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

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

revision 371 by jonathan, Mon Jan 27 13:49:39 2003 UTC revision 385 by jonathan, Mon Feb 3 11:43:56 2003 UTC
# Line 20  See the description of getProperties() f Line 20  See the description of getProperties() f
20  on the mapping algorithm.  on the mapping algorithm.
21  """  """
22        
23    from Thuban import _
24    from Thuban.Model.color import Color
25    
26    from wxPython.wx import *
27    
28  # constants  # constants
29  RANGE_MIN  = 0  RANGE_MIN  = 0
30  RANGE_MAX  = 1  RANGE_MAX  = 1
# Line 35  class Classification: Line 40  class Classification:
40                      is to be used to classify layer properties                      is to be used to classify layer properties
41          """          """
42    
43          self.__points = {}          self.points = {}
44          self.__ranges = []          self.ranges = []
45          self.setField(field)          self.setField(field)
46          self.setNull(None)          self.setNull(None)
47                    
# Line 56  class Classification: Line 61  class Classification:
61    
62          self.NullData = data          self.NullData = data
63    
64        def getNull(self):
65            return self.NullData
66    
67      def addRange(self, min, max, data):      def addRange(self, min, max, data):
68          """Add a new range to the classification.          """Add a new range to the classification.
69    
# Line 70  class Classification: Line 78  class Classification:
78          """          """
79    
80          if min >= max:          if min >= max:
81              raise ValueError("Range minimum >= maximum!")              raise ValueError(_("Range minimum >= maximum!"))
82          self.__ranges.append([min, max, data])          self.ranges.append([min, max, data])
83    
84      def addPoint(self, value, data):      def addPoint(self, value, data):
85          """Associate a single value with data.          """Associate a single value with data.
# Line 83  class Classification: Line 91  class Classification:
91             data  -- data that the value maps to. See class description.             data  -- data that the value maps to. See class description.
92          """          """
93    
94          self.__points[value] = data          self.points[value] = data
95    
96      def getProperties(self, value):      def getProperties(self, value):
97          """Return the associated data, or the NullData.          """Return the associated data, or the NullData.
# Line 103  class Classification: Line 111  class Classification:
111              #              #
112              # first check the discrete values              # first check the discrete values
113              #              #
114              if self.__points.has_key(value):              if self.points.has_key(value):
115                  return self.__points[value]                  return self.points[value]
116    
117              #              #
118              # now check the ranges              # now check the ranges
119              #              #
120              for p in self.__ranges:              for p in self.ranges:
121                  if (p[RANGE_MIN] <= value) and (value < p[RANGE_MAX]):                  if (p[RANGE_MIN] <= value) and (value < p[RANGE_MAX]):
122                      return p[RANGE_DATA]                      return p[RANGE_DATA]
123    
124    
125          return self.NullData          return self.NullData
126    
127        def TreeInfo(self):
128            items = []
129    
130            #
131            # shouldn't print anything if there are no classifications
132            #
133    
134            
135            def color_string(color):
136                if color is None:
137                    return "None"
138                return "(%.3f, %.3f, %.3f)" % (color.red, color.green, color.blue)
139    
140            if self.NullData is not None:
141                i = []
142                for key, value in self.NullData.items():
143                    if isinstance(value, Color):
144                        i.append((_("%s: %s") % (key, color_string(value)), value))
145                    else:
146                        i.append(_("%s: %s") % (key, value))
147                items.append((_("'NULL'"), i))
148    
149            for name, data in self.points.items():
150                i = []
151                for key, value in data.items():
152                    if isinstance(value, Color):
153                        i.append((_("%s: %s") % (key, color_string(value)), value))
154                    else:
155                        i.append(_("%s: %s") % (key, value))
156                items.append((_("%s") % name, i))
157    
158            for p in self.ranges:
159                i = []
160                data = p[RANGE_DATA]
161                for key, value in data.items():
162                    if isinstance(value, Color):
163                        i.append((_("%s: %s") % (key, color_string(value)), value))
164                    else:
165                        i.append(_("%s: %s") % (key, value))
166                items.append((_("%s-%s") % (p[RANGE_MIN], p[RANGE_MAX], i)))
167          
168            return (_("Classifications"), items)
169    

Legend:
Removed from v.371  
changed lines
  Added in v.385

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26