1 |
# Copyright (c) 2003 by Intevation GmbH |
# Copyright (c) 2003-2004 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Jonathan Coles <[email protected]> |
# Jan-Oliver Wagner <[email protected]> (2004) |
4 |
|
# Bernhard Herzog <[email protected]> (2003) |
5 |
|
# Thomas K�ster <[email protected]> (2003) |
6 |
|
# Jonathan Coles <[email protected]> (2003) |
7 |
# |
# |
8 |
# This program is free software under the GPL (>=v2) |
# This program is free software under the GPL (>=v2) |
9 |
# Read the file COPYING coming with Thuban for details. |
# Read the file COPYING coming with Thuban for details. |
144 |
max = _list[q] |
max = _list[q] |
145 |
|
|
146 |
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 |
|
147 |
|
|
|
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] |
|
|
|
|
|
group = ClassGroupRange(Range((start, min, max, end)), prop) |
|
|
|
|
148 |
group.SetLabel("%s%% - %s%%" % (round(oldp*100, 2), |
group.SetLabel("%s%% - %s%%" % (round(oldp*100, 2), |
149 |
round(p*100, 2))) |
round(p*100, 2))) |
150 |
oldp = p |
oldp = p |
153 |
clazz.AppendGroup(group) |
clazz.AppendGroup(group) |
154 |
i += 1 |
i += 1 |
155 |
|
|
156 |
return (adjusted, clazz, _list[class0[0]]) |
return (adjusted, clazz) |
157 |
|
|
158 |
|
|
159 |
def calculate_quantiles(_list, percents, _range): |
def calculate_quantiles(_list, percents, _range): |
160 |
"""Calculate quantiles for the given _list of percents from the |
"""Calculate quantiles for the given _list of percents from the |
161 |
sorted list of values that are in range. |
sorted list of values that are in range. |
162 |
|
|
163 |
This may not actually generate len(percents) quantiles if |
This may not actually generate len(percents) quantiles if |
164 |
many of the values that fall on quantile borders are the same. |
many of the values that fall on quantile borders are the same. |
165 |
|
|
348 |
+ self.prop1.GetLineWidth() |
+ self.prop1.GetLineWidth() |
349 |
newProps.SetLineWidth(int(round(w))) |
newProps.SetLineWidth(int(round(w))) |
350 |
|
|
351 |
|
s = (self.prop2.GetSize() - self.prop1.GetSize()) \ |
352 |
|
* index \ |
353 |
|
+ self.prop1.GetSize() |
354 |
|
newProps.SetSize(int(round(s))) |
355 |
|
|
356 |
return newProps |
return newProps |
357 |
|
|
358 |
def __SetProperty(self, color1, color2, index, setf): |
def __SetProperty(self, color1, color2, index, setf): |