/[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 381 by jonathan, Tue Jan 28 18:37:05 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 70  class Classification: Line 75  class Classification:
75          """          """
76    
77          if min >= max:          if min >= max:
78              raise ValueError("Range minimum >= maximum!")              raise ValueError(_("Range minimum >= maximum!"))
79          self.__ranges.append([min, max, data])          self.ranges.append([min, max, data])
80    
81      def addPoint(self, value, data):      def addPoint(self, value, data):
82          """Associate a single value with data.          """Associate a single value with data.
# Line 83  class Classification: Line 88  class Classification:
88             data  -- data that the value maps to. See class description.             data  -- data that the value maps to. See class description.
89          """          """
90    
91          self.__points[value] = data          self.points[value] = data
92    
93      def getProperties(self, value):      def getProperties(self, value):
94          """Return the associated data, or the NullData.          """Return the associated data, or the NullData.
# Line 103  class Classification: Line 108  class Classification:
108              #              #
109              # first check the discrete values              # first check the discrete values
110              #              #
111              if self.__points.has_key(value):              if self.points.has_key(value):
112                  return self.__points[value]                  return self.points[value]
113    
114              #              #
115              # now check the ranges              # now check the ranges
116              #              #
117              for p in self.__ranges:              for p in self.ranges:
118                  if (p[RANGE_MIN] <= value) and (value < p[RANGE_MAX]):                  if (p[RANGE_MIN] <= value) and (value < p[RANGE_MAX]):
119                      return p[RANGE_DATA]                      return p[RANGE_DATA]
120    
121    
122          return self.NullData          return self.NullData
123    
124        def TreeInfo(self):
125            items = []
126    
127            #
128            # shouldn't print anything if there are no classifications
129            #
130    
131            
132            def color_string(color):
133                if color is None:
134                    return "None"
135                return "(%.3f, %.3f, %.3f)" % (color.red, color.green, color.blue)
136    
137            if self.NullData is not None:
138                i = []
139                for key, value in self.NullData.items():
140                    if isinstance(value, Color):
141                        i.append((_("%s: %s") % (key, color_string(value)), value))
142                    else:
143                        i.append(_("%s: %s") % (key, value))
144                items.append((_("'NULL'"), i))
145    
146            for name, data in self.points.items():
147                i = []
148                for key, value in data.items():
149                    if isinstance(value, Color):
150                        i.append((_("%s: %s") % (key, color_string(value)), value))
151                    else:
152                        i.append(_("%s: %s") % (key, value))
153                items.append((_("%s") % name, i))
154    
155            for p in self.ranges:
156                i = []
157                data = p[RANGE_DATA]
158                for key, value in data.items():
159                    if isinstance(value, Color):
160                        i.append((_("%s: %s") % (key, color_string(value)), value))
161                    else:
162                        i.append(_("%s: %s") % (key, value))
163                items.append((_("%s-%s") % (p[RANGE_MIN], p[RANGE_MAX], i)))
164          
165            return (_("Classifications"), items)
166    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26