23 |
|
|
24 |
ID_CLASSGEN_GEN = 4001 |
ID_CLASSGEN_GEN = 4001 |
25 |
ID_CLASSGEN_CLOSE = 4002 |
ID_CLASSGEN_CLOSE = 4002 |
26 |
ID_CLASSGEN_COMBO = 4007 |
ID_CLASSGEN_GENCOMBO = 4007 |
27 |
|
ID_CLASSGEN_PROPCOMBO = 4008 |
28 |
|
|
29 |
COMBOSTR_UNIFORM = _("Uniform Distribution") |
GENCOMBOSTR_UNIFORM = _("Uniform Distribution") |
30 |
COMBOSTR_UNIQUE = _("Unique Values") |
GENCOMBOSTR_UNIQUE = _("Unique Values") |
31 |
|
|
32 |
|
PROPCOMBOSTR_CUSTOM = _("Custom Ramp") |
33 |
|
PROPCOMBOSTR_RED = _("Red Ramp") |
34 |
|
PROPCOMBOSTR_GREEN = _("Green Ramp") |
35 |
|
PROPCOMBOSTR_BLUE = _("Blue Ramp") |
36 |
|
|
37 |
class ClassGenDialog(wxDialog): |
class ClassGenDialog(wxDialog): |
38 |
|
|
74 |
0, wxALL, 4) |
0, wxALL, 4) |
75 |
|
|
76 |
psizer = wxBoxSizer(wxHORIZONTAL) |
psizer = wxBoxSizer(wxHORIZONTAL) |
77 |
psizer.Add(wxStaticText( |
psizer.Add(wxStaticText(self, -1, _("Generate:")), |
|
self, -1, |
|
|
_("Generate:")), |
|
78 |
0, wxALIGN_CENTER_VERTICAL, 0) |
0, wxALIGN_CENTER_VERTICAL, 0) |
79 |
|
|
80 |
self.genCombo = wxComboBox(self, |
self.genCombo = wxComboBox(self, |
81 |
ID_CLASSGEN_COMBO, |
ID_CLASSGEN_GENCOMBO, |
82 |
"", style = wxCB_READONLY) |
"", style = wxCB_READONLY) |
83 |
psizer.Add(self.genCombo, 1, wxALL | wxGROW, 4) |
psizer.Add(self.genCombo, 1, wxALL | wxGROW, 4) |
84 |
EVT_COMBOBOX(self, ID_CLASSGEN_COMBO, self._OnGenTypeSelect) |
EVT_COMBOBOX(self, ID_CLASSGEN_GENCOMBO, self._OnGenTypeSelect) |
85 |
|
|
86 |
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
87 |
|
|
90 |
self.genPanel = None |
self.genPanel = None |
91 |
|
|
92 |
panel = GenUniquePanel(self, layer, fieldName, self.type) |
panel = GenUniquePanel(self, layer, fieldName, self.type) |
93 |
self.genCombo.Append(COMBOSTR_UNIQUE) |
self.genCombo.Append(GENCOMBOSTR_UNIQUE, panel) |
|
self.genCombo.SetClientData(self.genCombo.GetCount() - 1, panel) |
|
94 |
sizer.Add(panel, 1, wxGROW | wxALL, 4) |
sizer.Add(panel, 1, wxGROW | wxALL, 4) |
95 |
|
|
96 |
self.genPanel = panel |
self.genPanel = panel |
97 |
|
|
98 |
if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE): |
if self.type in (FIELDTYPE_INT, FIELDTYPE_DOUBLE): |
99 |
panel = GenUniformPanel(self, layer, fieldName, self.type) |
panel = GenUniformPanel(self, layer, fieldName, self.type) |
100 |
self.genCombo.Append(COMBOSTR_UNIFORM) |
self.genCombo.Append(GENCOMBOSTR_UNIFORM, panel) |
|
self.genCombo.SetClientData(self.genCombo.GetCount() - 1, panel) |
|
101 |
sizer.Add(panel, 0, wxGROW | wxALL, 4) |
sizer.Add(panel, 0, wxGROW | wxALL, 4) |
102 |
sizer.Show(panel, False) |
sizer.Show(panel, False) |
103 |
|
|
104 |
############# |
############# |
105 |
|
|
106 |
self.propPanel = None |
psizer = wxBoxSizer(wxHORIZONTAL) |
107 |
|
psizer.Add(wxStaticText(self, -1, _("Color Schemes:")), |
108 |
|
0, wxALIGN_CENTER_VERTICAL, 0) |
109 |
|
|
110 |
panel = CustomRampPanel(self, layer.ShapeType()) |
self.propCombo = wxComboBox(self, |
111 |
|
ID_CLASSGEN_PROPCOMBO, |
112 |
|
"", style = wxCB_READONLY) |
113 |
|
psizer.Add(self.propCombo, 1, wxALL | wxGROW, 4) |
114 |
|
EVT_COMBOBOX(self, ID_CLASSGEN_PROPCOMBO, self._OnPropTypeSelect) |
115 |
|
sizer.Add(psizer, 0, wxALL | wxGROW, 4) |
116 |
|
|
117 |
self.propPanel = panel |
############# |
118 |
|
|
119 |
|
self.propPanel = None |
120 |
|
panel = CustomRampPanel(self, layer.ShapeType()) |
121 |
sizer.Add(panel, 1, wxALL | wxGROW, 4) |
sizer.Add(panel, 1, wxALL | wxGROW, 4) |
122 |
|
sizer.Show(panel, False) |
123 |
|
|
124 |
|
self.propCombo.Append(PROPCOMBOSTR_RED, RedRamp()) |
125 |
|
self.propCombo.Append(PROPCOMBOSTR_GREEN, GreenRamp()) |
126 |
|
self.propCombo.Append(PROPCOMBOSTR_BLUE, BlueRamp()) |
127 |
|
self.propCombo.Append(PROPCOMBOSTR_CUSTOM, panel) |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
############# |
############# |
132 |
|
|
151 |
|
|
152 |
def _OnGenerate(self, event): |
def _OnGenerate(self, event): |
153 |
|
|
154 |
selIndex = self.genCombo.GetSelection() |
index = self.genCombo.GetSelection() |
155 |
|
|
156 |
sel = self.genCombo.GetString(selIndex) |
genSel = self.genCombo.GetString(index) |
157 |
genPanel = self.genCombo.GetClientData(selIndex) |
genPanel = self.genCombo.GetClientData(index) |
|
propPanel = self.propPanel |
|
158 |
|
|
159 |
if sel == COMBOSTR_UNIFORM: |
propPanel = self.propPanel |
160 |
|
|
161 |
min = genPanel.GetMin() |
if genSel in (GENCOMBOSTR_UNIFORM, GENCOMBOSTR_UNIQUE): |
|
max = genPanel.GetMax() |
|
162 |
numGroups = genPanel.GetNumGroups() |
numGroups = genPanel.GetNumGroups() |
|
sp = propPanel.GetStartProperties() |
|
|
ep = propPanel.GetEndProperties() |
|
163 |
|
|
164 |
if min is not None \ |
index = self.propCombo.GetSelection() |
|
and max is not None \ |
|
|
and numGroups is not None: |
|
165 |
|
|
166 |
self.clazz = ClassGenerator().GenUnifromDistribution( |
propSel = self.propCombo.GetString(index) |
167 |
min, max, numGroups, sp, ep, |
propPanel = self.propCombo.GetClientData(index) |
|
self.type == FIELDTYPE_INT) |
|
168 |
|
|
169 |
self.parent._SetClassification(self.clazz) |
ramp = propPanel.GetRamp() |
170 |
|
|
171 |
elif sel == COMBOSTR_UNIQUE: |
if genSel == GENCOMBOSTR_UNIFORM: |
172 |
|
|
173 |
list = genPanel.GetValueList() |
min = genPanel.GetMin() |
174 |
numGroups = genPanel.GetNumGroups() |
max = genPanel.GetMax() |
|
sp = propPanel.GetStartProperties() |
|
|
ep = propPanel.GetEndProperties() |
|
175 |
|
|
176 |
if len(list) > 0 \ |
if min is not None \ |
177 |
and numGroups is not None: |
and max is not None \ |
178 |
|
and numGroups is not None: |
179 |
|
|
180 |
self.clazz = ClassGenerator().GenSingletonsFromList( |
self.clazz = ClassGenerator().GenUnifromDistribution( |
181 |
list, numGroups, sp, ep) |
min, max, numGroups, ramp, |
182 |
|
self.type == FIELDTYPE_INT) |
183 |
|
|
184 |
self.parent._SetClassification(self.clazz) |
self.parent._SetClassification(self.clazz) |
185 |
|
|
186 |
else: |
elif genSel == GENCOMBOSTR_UNIQUE: |
187 |
pass |
|
188 |
|
list = genPanel.GetValueList() |
189 |
|
|
190 |
|
if len(list) > 0 \ |
191 |
|
and numGroups is not None: |
192 |
|
|
193 |
|
self.clazz = ClassGenerator().GenSingletonsFromList( |
194 |
|
list, numGroups, ramp) |
195 |
|
|
196 |
|
self.parent._SetClassification(self.clazz) |
197 |
|
|
198 |
def _OnCloseBtn(self, event): |
def _OnCloseBtn(self, event): |
199 |
self.Close() |
self.Close() |
214 |
self.sizer.SetSizeHints(self) |
self.sizer.SetSizeHints(self) |
215 |
self.sizer.Layout() |
self.sizer.Layout() |
216 |
|
|
217 |
|
def _OnPropTypeSelect(self, event): |
218 |
|
combo = event.GetEventObject() |
219 |
|
|
220 |
|
selIndex = combo.GetSelection() |
221 |
|
sel = combo.GetString(selIndex) |
222 |
|
|
223 |
|
if isinstance(self.propPanel, wxPanel): |
224 |
|
self.sizer.Show(self.propPanel, False) |
225 |
|
|
226 |
|
self.propPanel = combo.GetClientData(selIndex) |
227 |
|
|
228 |
|
if isinstance(self.propPanel, wxPanel): |
229 |
|
self.sizer.Show(self.propPanel, True) |
230 |
|
|
231 |
|
self.sizer.SetSizeHints(self) |
232 |
|
self.sizer.Layout() |
233 |
|
|
234 |
|
|
235 |
ID_UNIFORM_MIN = 4001 |
ID_UNIFORM_MIN = 4001 |
236 |
ID_UNIFORM_MAX = 4002 |
ID_UNIFORM_MAX = 4002 |
734 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
735 |
topSizer.SetSizeHints(self) |
topSizer.SetSizeHints(self) |
736 |
|
|
737 |
def GetStartProperties(self): |
def GetRamp(self): |
738 |
return self.startPropCtrl.GetProperties() |
return CustomRamp(self.startPropCtrl.GetProperties(), |
739 |
|
self.endPropCtrl.GetProperties()) |
|
def GetEndProperties(self): |
|
|
return self.endPropCtrl.GetProperties() |
|
740 |
|
|
741 |
def _OnCopyStart(self, event): |
def _OnCopyStart(self, event): |
742 |
self.endPropCtrl.SetProperties(self.startPropCtrl.GetProperties()) |
self.endPropCtrl.SetProperties(self.startPropCtrl.GetProperties()) |
752 |
|
|
753 |
class ClassGenerator: |
class ClassGenerator: |
754 |
|
|
755 |
def GenSingletonsFromList(self, list, numGroups, prop1, prop2): |
def GenSingletonsFromList(self, list, numGroups, ramp): |
756 |
"""Generate a new classification consisting solely of singletons. |
"""Generate a new classification consisting solely of singletons. |
757 |
|
|
758 |
The resulting classification will consist of at most 'numGroups' |
The resulting classification will consist of at most 'numGroups' |
774 |
clazz = Classification() |
clazz = Classification() |
775 |
if numGroups == 0: return clazz |
if numGroups == 0: return clazz |
776 |
|
|
777 |
for value, prop in zip(list, CustomRamp(numGroups, prop1, prop2)): |
ramp.SetNumGroups(numGroups) |
778 |
|
|
779 |
|
for value, prop in zip(list, ramp): |
780 |
clazz.AppendGroup(ClassGroupSingleton(value, prop)) |
clazz.AppendGroup(ClassGroupSingleton(value, prop)) |
781 |
|
|
782 |
return clazz |
return clazz |
783 |
|
|
784 |
def GenSingletons(self, min, max, numGroups, prop1, prop2): |
def GenSingletons(self, min, max, numGroups, ramp): |
785 |
|
|
786 |
clazz = Classification() |
clazz = Classification() |
787 |
|
|
791 |
if numGroups > 0: |
if numGroups > 0: |
792 |
cur_value = min |
cur_value = min |
793 |
|
|
794 |
for prop in CustomRamp(numGroups, prop1, prop2): |
ramp.SetNumGroups(numGroups) |
795 |
|
|
796 |
|
for prop in ramp: |
797 |
clazz.AppendGroup( |
clazz.AppendGroup( |
798 |
ClassGroupSingleton( |
ClassGroupSingleton( |
799 |
Str2Num(str(cur_value)), |
Str2Num(str(cur_value)), |
803 |
return clazz |
return clazz |
804 |
|
|
805 |
def GenUnifromDistribution(self, min, max, numGroups, |
def GenUnifromDistribution(self, min, max, numGroups, |
806 |
prop1, prop2, intStep = False): |
ramp, intStep = False): |
807 |
"""Generate a classification with numGroups range groups |
"""Generate a classification with numGroups range groups |
808 |
each with the same interval. |
each with the same interval. |
809 |
|
|
816 |
clazz = Classification() |
clazz = Classification() |
817 |
if numGroups == 0: return clazz |
if numGroups == 0: return clazz |
818 |
|
|
819 |
|
ramp.SetNumGroups(numGroups) |
820 |
|
|
821 |
step = Str2Num(str((max - min) / float(numGroups))) |
step = Str2Num(str((max - min) / float(numGroups))) |
822 |
|
|
823 |
if intStep: |
if intStep: |
827 |
cur_max = cur_min + step |
cur_max = cur_min + step |
828 |
|
|
829 |
i = 0 |
i = 0 |
830 |
for prop in CustomRamp(numGroups, prop1, prop2): |
for prop in ramp: |
831 |
|
|
832 |
if i == (numGroups - 1): |
if i == (numGroups - 1): |
833 |
cur_max = max |
cur_max = max |
850 |
STEP = 1 |
STEP = 1 |
851 |
class CustomRamp: |
class CustomRamp: |
852 |
|
|
853 |
def __init__(self, num, prop1, prop2): |
def __init__(self, prop1, prop2): |
854 |
|
self.prop1 = prop1 |
855 |
|
self.prop2 = prop2 |
856 |
|
|
857 |
|
self.count = 0 |
858 |
|
|
859 |
|
def __iter__(self): |
860 |
|
return self |
861 |
|
|
862 |
|
def GetRamp(self): |
863 |
|
return self |
864 |
|
|
865 |
|
def SetNumGroups(self, num): |
866 |
|
|
867 |
|
if num <= 0: |
868 |
|
return False |
869 |
|
|
870 |
self.count = int(num) |
self.count = int(num) |
871 |
num = float(num) |
num = float(num) |
872 |
|
|
873 |
|
prop1 = self.prop1 |
874 |
|
prop2 = self.prop2 |
875 |
|
|
876 |
clr = prop1.GetLineColor() |
clr = prop1.GetLineColor() |
877 |
lineColor2 = prop2.GetLineColor() |
lineColor2 = prop2.GetLineColor() |
878 |
|
|
891 |
self.lineWidth = prop1.GetLineWidth() |
self.lineWidth = prop1.GetLineWidth() |
892 |
self.lineWidthStep = (prop2.GetLineWidth() - self.lineWidth) / num |
self.lineWidthStep = (prop2.GetLineWidth() - self.lineWidth) / num |
893 |
|
|
894 |
def __iter__(self): |
return True |
|
return self |
|
895 |
|
|
896 |
def next(self): |
def next(self): |
897 |
if self.count == 0: |
if self.count == 0: |
956 |
|
|
957 |
|
|
958 |
return (color, step) |
return (color, step) |
959 |
|
|
960 |
|
class MonochromaticRamp(CustomRamp): |
961 |
|
def __init__(self, start, end): |
962 |
|
sp = ClassGroupProperties() |
963 |
|
sp.SetLineColor(start) |
964 |
|
sp.SetFill(start) |
965 |
|
|
966 |
|
ep = ClassGroupProperties() |
967 |
|
ep.SetLineColor(end) |
968 |
|
ep.SetFill(end) |
969 |
|
|
970 |
|
CustomRamp.__init__(self, sp, ep) |
971 |
|
|
972 |
|
class RedRamp(MonochromaticRamp): |
973 |
|
def __init__(self): |
974 |
|
MonochromaticRamp.__init__(self, Color(.2, 0, 0), Color(1, 0, 0)) |
975 |
|
|
976 |
|
class GreenRamp(MonochromaticRamp): |
977 |
|
def __init__(self): |
978 |
|
MonochromaticRamp.__init__(self, Color(0, .2, 0), Color(0, 1, 0)) |
979 |
|
|
980 |
|
class BlueRamp(MonochromaticRamp): |
981 |
|
def __init__(self): |
982 |
|
MonochromaticRamp.__init__(self, Color(0, 0, .2), Color(0, 0, 1)) |
983 |
|
|