-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathClassRender.cs
240 lines (138 loc) · 5.05 KB
/
ClassRender.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.GlobeCore;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesGDB;
namespace EngineApplication
{
public class ClassRender
{
public ClassRender(AxMapControl pMapControl, IFeatureLayer pFtLayer, int ClassCount, string pFieldName)
{
IGeoFeatureLayer pGeolayer;
IActiveView pActiveView;
pGeolayer = pFtLayer as IGeoFeatureLayer;
pActiveView = pMapControl.ActiveView;
//以下是为了统计和分类所需要的对象
ITable pTable;
IClassifyGEN pClassify;//C#要用这个不同于VB中的,分类对象。
ITableHistogram pTableHist;//相当于一个统计表
IBasicHistogram pBasicHist;//这个对象有一个很重要的方法
double[] ClassNum;
int ClassCountResult;//返回分类个数。
IHsvColor pFromColor;
IHsvColor pToColor;//用于构建另外一个颜色带对象。
IAlgorithmicColorRamp pAlgo;
pTable = pGeolayer as ITable;
IMap pMap;
pMap = pMapControl.Map;
pMap.ReferenceScale = 0;
pBasicHist = new BasicTableHistogramClass();//也可以实例化 pTableHist。学会这个灵活的思维
pTableHist = pBasicHist as ITableHistogram;
pTableHist.Table = pTable;
pTableHist.Field = pFieldName;
object datavalus;
object Frenquen;
pBasicHist.GetHistogram(out datavalus,out Frenquen);//获得数据和相应的频数。
pClassify = new EqualIntervalClass();
try
{
pClassify.Classify(datavalus, Frenquen, ref ClassCount);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
// 分类完成
ClassNum = (double[])pClassify.ClassBreaks;
ClassCountResult = ClassNum.GetUpperBound(0);//返回分级个数。
IClassBreaksRenderer pClassBreak;
pClassBreak = new ClassBreaksRendererClass();
pClassBreak.Field = pFieldName;
pClassBreak.BreakCount = ClassCountResult;
pClassBreak.SortClassesAscending = true;
pAlgo = new AlgorithmicColorRampClass();
pAlgo.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;
pFromColor = Hsv(60, 100, 96);
pToColor = Hsv(0, 100, 96);
pAlgo.FromColor = pFromColor;
pAlgo.ToColor = pToColor;
pAlgo.Size = ClassCountResult;
bool ok;
pAlgo.CreateRamp(out ok);
IEnumColors pEnumColor;
pEnumColor = pAlgo.Colors;
pEnumColor.Reset();
IColor pColor;
ISimpleFillSymbol pSimFill;
/* IRgbColor[] pRgbColor;//可以构造颜色
pRgbColor = new IRgbColor[ClassCountResult];
for (int j = 0; j < ClassCountResult; j++)
{
int R = 50;
int G = 100;
int B = 50;
R = R + 50;
if (R > 250)
{
R = 50;
}
if (G > 250)
{
G = 100;
}
if (B > 250)
{
B = 50;
}
G = G + 100;
B = B + 50;
pRgbColor[j] = ColorRgb(R, G, B);
}
*/
for (int indexColor = 0; indexColor <= ClassCountResult - 1; indexColor++)
{
pColor = pEnumColor.Next();
pSimFill = new SimpleFillSymbolClass();
pSimFill.Color = pColor;
// pSimFill.Color = pRgbColor[indexColor ];
pSimFill.Style = esriSimpleFillStyle.esriSFSSolid;
//染色
pClassBreak.set_Symbol(indexColor, pSimFill as ISymbol);
pClassBreak.set_Break(indexColor, ClassNum[indexColor + 1]);
}
pGeolayer.Renderer = pClassBreak as IFeatureRenderer;
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
}
public IHsvColor Hsv(int hue, int saturation, int val)
{
IHsvColor pHsvC;
pHsvC = new HsvColorClass();
pHsvC.Hue = hue;
pHsvC.Saturation = saturation;
pHsvC.Value = val;
return pHsvC;
}
public IRgbColor ColorRgb(int r, int g, int b)
{
IRgbColor pRGB;
pRGB = new RgbColorClass();
pRGB.Red = r;
pRGB.Green = g;
pRGB.Blue = b;
return pRGB;
}
}
}