参考代码1
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
|
private
void
分级渲染ToolStripMenuItem_Click(
object
sender, EventArgs e)
{
//值分级
IBasicHistogram pBasicHis =
new
BasicTableHistogramClass();
ITableHistogram pTabHis = (ITableHistogram)pBasicHis;
pTabHis.Field =
"w1"
;
ITable pTab = (ITable)axMapControl1.get_Layer(0);
pTabHis.Table = pTab;
object
doubleArrVal, longArrFreq;
pBasicHis.GetHistogram(
out
doubleArrVal,
out
longArrFreq);
IClassifyGEN pClassify =
new
EqualIntervalClass();
//NaturalBreaksClass
int
nDes = 5;
pClassify.Classify(doubleArrVal, longArrFreq,
ref
nDes);
object
classes = pClassify.ClassBreaks;
System.Array pArr = (System.Array)classes;
//算法梯度颜色
IAlgorithmicColorRamp pAlgoColorRamp =
new
AlgorithmicColorRampClass();
pAlgoColorRamp.Size = pArr.Length;
IRgbColor pFromColor =
new
RgbColorClass(), pToColor =
new
RgbColorClass();
pFromColor.Red = 0;
pFromColor.Green = 255;
pFromColor.Blue = 0;
pToColor.Red = 255;
pToColor.Green = 0;
pToColor.Blue = 255;
pAlgoColorRamp.FromColor = pFromColor;
pAlgoColorRamp.ToColor = pToColor;
bool
ok =
true
;
pAlgoColorRamp.CreateRamp(
out
ok);
//颜色梯度结束
IClassBreaksRenderer pRender =
new
ClassBreaksRendererClass();
pRender.BreakCount = pArr.Length;
pRender.Field =
"w1"
;
ISimpleFillSymbol pSym;
for
(
int
i = 0; i < pArr.Length; i++)
{
pRender.set_Break(i, (
double
)pArr.GetValue(i));
pSym =
new
SimpleFillSymbolClass();
pSym.Color = pAlgoColorRamp.get_Color(i);
pRender.set_Symbol(i, (ISymbol)pSym);
}
IGeoFeatureLayer pGeoLyr = (IGeoFeatureLayer)axMapControl1.get_Layer(0);
pGeoLyr.Renderer = (IFeatureRenderer)pRender;
axMapControl1.Refresh();
axTOCControl1.Update();
}
|
参考代码2
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
|
private
void
分层设色ToolStripMenuItem_Click(
object
sender, EventArgs e)
{
//获取当前图层 ,并把它设置成IGeoFeatureLayer的实例
IMap pMap = axMapControl1.Map;
ILayer pLayer = pMap.get_Layer(0)
as
IFeatureLayer;
IFeatureLayer pFeatureLayer = pLayer
as
IFeatureLayer;
IGeoFeatureLayer pGeoFeatureLayer = pLayer
as
IGeoFeatureLayer;
//获取图层上的feature
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
IFeatureCursor pFeatureCursor = pFeatureClass.Search(
null
,
false
);
IFeature pFeature = pFeatureCursor.NextFeature();
//
IFeatureRenderer PR=pGeoFeatureLayer.Renderer;<br>
//JoinData("县级区域", "DZGB", "sectioncode"); //join外部表
// int DC ;
int
desiredClasses = 5;
string
fieldName =
"w1"
;
int
classesCount;
double
[] classes;
string
strOutput =
""
;
bool
ok;
object
dataFrequency;
object
dataValues;
ITable pTable ;
//IClassify pClassify;
EqualIntervalClass pClassify;
//IBasicHistogram pTableHistogram = new BasicTableHistogramClass();
//IHistogram pTableHistogram = new BasicTableHistogramClass();
ITableHistogram pTableHistogram =
new
BasicTableHistogramClass()
as
ITableHistogram;
IBasicHistogram pHistogram;
IClassBreaksRenderer pClassBreaksRenderer;
IHsvColor pFromColor;
IHsvColor pToColor;
IAlgorithmicColorRamp pAlgorithmicColorRamp;
IEnumColors pEnumColors;
IColor pColor;
ISimpleFillSymbol pSimpleFillSymbol;
pLayer = (IFeatureLayer)axMapControl1.get_Layer(0);
pGeoFeatureLayer = (IGeoFeatureLayer)pLayer;
pTable = (ITable)pGeoFeatureLayer;
pHistogram = (IBasicHistogram)pTableHistogram;
// Get values and frequencies for the field
pTableHistogram.Field = fieldName;
pTableHistogram.Table = pTable;
pHistogram.GetHistogram(
out
dataValues,
out
dataFrequency);
// Put values and frequencies into an Equal Interval Classify Object
pClassify =
new
EqualIntervalClass();
//pClassify = new NaturalBreaksClass();
pClassify.SetHistogramData(dataValues, dataFrequency);
pClassify.Classify(dataValues, dataFrequency,
ref
desiredClasses);
//pClassify.Classify(ref desiredClasses);
classes = (
double
[])pClassify.ClassBreaks;
classesCount = classes.Length;
// Initialise a new Class Breaks renderer
// Supply the number of Class Breaks and the field to perform. the class breaks on
pClassBreaksRenderer =
new
ClassBreaksRendererClass();
pClassBreaksRenderer.Field = fieldName;
pClassBreaksRenderer.BreakCount = classesCount;
pClassBreaksRenderer.SortClassesAscending =
true
;
// Use algorithmic color ramp to generate an range of colors between YELLOW to RED
// Initial color: YELLOW
pFromColor =
new
HsvColorClass();
pFromColor.Hue = 60;
pFromColor.Saturation = 100;
pFromColor.Value = 96;
// Final color: RED
pToColor =
new
HsvColorClass();
pToColor.Hue = 0;
pToColor.Saturation = 100;
pToColor.Value = 96;
// Set up HSV Color ramp to span from YELLOW to RED
pAlgorithmicColorRamp =
new
AlgorithmicColorRampClass();
pAlgorithmicColorRamp.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;
pAlgorithmicColorRamp.FromColor = pFromColor;
pAlgorithmicColorRamp.ToColor = pToColor;
pAlgorithmicColorRamp.Size = classesCount;
pAlgorithmicColorRamp.CreateRamp(
out
ok);
pEnumColors = pAlgorithmicColorRamp.Colors;
for
(
int
index = 0; index < classesCount - 1; index++)
{
pColor = pEnumColors.Next();
pSimpleFillSymbol =
new
SimpleFillSymbolClass();
pSimpleFillSymbol.Color = pColor;
pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
pClassBreaksRenderer.set_Symbol(index, (ISymbol)pSimpleFillSymbol);
pClassBreaksRenderer.set_Break(index, classes[index + 1]);
// Store each break value for user output
strOutput +=
"-"
+ classes[index + 1] +
"\n"
;
}
pGeoFeatureLayer.Renderer = (IFeatureRenderer)pClassBreaksRenderer;
//this.axMapControl1.Refresh();<br>
/////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
//get the custom property from which is supposed to be the layer to be saved
object
customProperty =
null
;
//IMapControl3 mapControl = null;
customProperty = axMapControl1.CustomProperty;
//ask the user to set a name for the new layer file
SaveFileDialog saveFileDialog =
new
SaveFileDialog();
saveFileDialog.Filter =
"Layer File|*.lyr|All Files|*.*"
;
saveFileDialog.Title =
"生成专题图"
;
saveFileDialog.RestoreDirectory =
true
;
saveFileDialog.FileName = System.IO.Path.Combine(saveFileDialog.InitialDirectory, pGeoFeatureLayer.Name +
".lyr"
);
//get the layer name from the user
DialogResult dr = saveFileDialog.ShowDialog();
if
(saveFileDialog.FileName !=
""
&& dr == DialogResult.OK)
{
if
(System.IO.File.Exists(saveFileDialog.FileName))
{
//try to delete the existing file
System.IO.File.Delete(saveFileDialog.FileName);
}
//create a new LayerFile instance
ILayerFile layerFile =
new
LayerFileClass();
//create a new layer file
layerFile.New(saveFileDialog.FileName);
//attach the layer file with the actual layer
layerFile.ReplaceContents((ILayer)pGeoFeatureLayer);
//save the layer file
layerFile.Save();
//ask the user whether he'd like to add the layer to the map
if
(DialogResult.Yes == MessageBox.Show(
"Would you like to add the layer to the map?"
,
"Message"
, MessageBoxButtons.YesNo,MessageBoxIcon.Question))
{
axMapControl1.AddLayerFromFile(saveFileDialog.FileName, 0);
}
}
IActiveView pActiveView = axMapControl1.Map
as
IActiveView;
pActiveView.Refresh();
axTOCControl1.Update();
}
|
参考代码3
View Code
参考代码4
View Code
没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。
本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/5903535.html,如需转载请自行联系原作者