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

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

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

trunk/thuban/Thuban/Model/classgen.py revision 1525 by jonathan, Wed Jul 30 15:42:56 2003 UTC branches/WIP-pyshapelib-bramz/Thuban/Model/classgen.py revision 2734 by bramz, Thu Mar 1 12:42:59 2007 UTC
# Line 1  Line 1 
1  # Copyright (c) 2003 by Intevation GmbH  # -*- encoding: iso-8859-1 -*-
2    #
3    # Copyright (c) 2003-2004 by Intevation GmbH
4  # Authors:  # Authors:
5  # Jonathan Coles <[email protected]>  # Jan-Oliver Wagner <[email protected]> (2004)
6    # Bernhard Herzog <[email protected]> (2003)
7    # Thomas K�ster <[email protected]> (2003)
8    # Jonathan Coles <[email protected]> (2003)
9  #  #
10  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
11  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
# Line 141  def generate_quantiles(_list, percents, Line 146  def generate_quantiles(_list, percents,
146                      max = _list[q]                      max = _list[q]
147    
148                  group = ClassGroupRange(Range((start, min, max, end)), prop)                  group = ClassGroupRange(Range((start, min, max, end)), prop)
       
                 group.SetLabel("%s%% - %s%%" % (round(oldp*100, 2),  
                                                 round(p*100, 2)))  
                 oldp = p  
                 start = "]"  
                 min = max  
                 clazz.AppendGroup(group)  
                 i += 1  
   
     return (adjusted, clazz)  
   
 def GenQuantiles0(_list, percents, ramp, _range):  
     """Same as GenQuantiles, but the first class won't be added to  
     the classification.  
   
     Returns a tuple (adjusted, Classification, upper_class0) where  
     upper_class0 is the highest value inside the first class.  
   
     _list -- a sort list of values  
   
     percents -- a sorted list of floats in the range 0.0-1.0 which  
                 represent the upper bound of each quantile. the  
                 union of all percentiles should be the entire  
                 range from 0.0-1.0  
   
     ramp -- an object which implements the CustomRamp interface  
   
     _range -- a Range object  
   
     Raises a Value Error if 'percents' has fewer than two items, or  
     does not cover the entire range.  
     """  
   
     clazz = Classification()  
     quantiles = calculate_quantiles(_list, percents, _range)  
     adjusted = True  
   
     if quantiles is not None:  
   
         numGroups = len(quantiles[3]) - 1  
   
         if numGroups > 0:  
             adjusted = quantiles[0]  
   
             start, min, endMax, right = _range.GetRange()  
   
             class0 = quantiles[3][0]  
             min = _list[class0[0]]  
             oldp = class0[1]  
             i = 1  
             end = "]"  
   
             maxValue = float(numGroups - 1)  
             if maxValue < 1: maxValue = 1  
             for (q, p) in quantiles[3][1:]:  
                 prop = ramp.GetProperties(float(i-1) / maxValue)  
   
                 if i == numGroups:  
                     max = endMax  
                     end = right  
                 else:  
                     max = _list[q]  
149    
                 group = ClassGroupRange(Range((start, min, max, end)), prop)  
       
150                  group.SetLabel("%s%% - %s%%" % (round(oldp*100, 2),                  group.SetLabel("%s%% - %s%%" % (round(oldp*100, 2),
151                                                  round(p*100, 2)))                                                  round(p*100, 2)))
152                  oldp = p                  oldp = p
# Line 214  def GenQuantiles0(_list, percents, ramp, Line 155  def GenQuantiles0(_list, percents, ramp,
155                  clazz.AppendGroup(group)                  clazz.AppendGroup(group)
156                  i += 1                  i += 1
157    
158      return (adjusted, clazz, _list[class0[0]])      return (adjusted, clazz)
159    
160    
161  def calculate_quantiles(_list, percents, _range):  def calculate_quantiles(_list, percents, _range):
162      """Calculate quantiles for the given _list of percents from the      """Calculate quantiles for the given _list of percents from the
163      sorted list of values that are in range.      sorted list of values that are in range.
164                                                                                
165      This may not actually generate len(percents) quantiles if      This may not actually generate len(percents) quantiles if
166      many of the values that fall on quantile borders are the same.      many of the values that fall on quantile borders are the same.
167    
# Line 409  class CustomRamp: Line 350  class CustomRamp:
350              + self.prop1.GetLineWidth()              + self.prop1.GetLineWidth()
351          newProps.SetLineWidth(int(round(w)))          newProps.SetLineWidth(int(round(w)))
352    
353            s = (self.prop2.GetSize() - self.prop1.GetSize()) \
354                * index \
355                + self.prop1.GetSize()
356            newProps.SetSize(int(round(s)))
357    
358          return newProps          return newProps
359    
360      def __SetProperty(self, color1, color2, index, setf):      def __SetProperty(self, color1, color2, index, setf):

Legend:
Removed from v.1525  
changed lines
  Added in v.2734

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26