-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeometryOperator.cs
229 lines (197 loc) · 9.28 KB
/
GeometryOperator.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Output;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Analyst3D;
using CSProject;
namespace MapControlApplication1
{
public class GeometryOperator
{
//===成员变量的声明================
public IMap m_map;
public MainForm m_form;
IPointCollection pointCollection;
IGraphicsContainer pGraphicsContainer;
//传入当前地图对象
public GeometryOperator(IMap map,MainForm form)
{
m_map = map; //map相当于一个mxd文件,其中包含许多的shp
m_form = form;
}
public void ShowGeometry(IGeometry geometry)
{
//强制转换,将Geometry对象转化为pointCollection
pointCollection = (Polygon)geometry;
DataTable dataTable = new DataTable();
DataColumn dataColumn = new DataColumn();
//===创建一个有三列的表格====================
dataColumn = new DataColumn();
dataColumn.ColumnName = "number";//设置第一列,表示用户指定的列名
dataColumn.DataType = System.Type.GetType("System.String");
dataColumn.ReadOnly = true; //第一列无法修改
dataTable.Columns.Add(dataColumn);
dataColumn = new DataColumn();
dataColumn.ColumnName = "X";//设置第二列为在目标图层类作为分类标准的属性
dataColumn.DataType = System.Type.GetType("System.String");
dataTable.Columns.Add(dataColumn);
dataColumn = new DataColumn();
dataColumn.ColumnName = "Y";//设置第三列为在目标图层类作为分类标准的属性
dataColumn.DataType = System.Type.GetType("System.String");
dataTable.Columns.Add(dataColumn);
//提供一个图形的容器
pGraphicsContainer = m_map as IGraphicsContainer;//只在本函数
DataRow dataRow;
for (int i = 0; i < pointCollection.PointCount; i++)
{
dataRow = dataTable.NewRow();
dataRow[0] = i+1;
dataRow[1] = Math.Round(pointCollection.Point[i].X,3);
dataRow[2] = Math.Round(pointCollection.Point[i].Y,3);//将统计结果添加到第三列
dataTable.Rows.Add(dataRow);
/*IElement pElement = new MarkerElementClass();
pElement.Geometry = pointCollection.Point[i];
pGraphicsContainer.AddElement(pElement, 0);//0 represents z-order */
//确定Element对象,并将对象加载到pGraphicsContainer中
IMarkerSymbol markerSymbol = new SimpleMarker3DSymbolClass();
//markerSymbol的类型和分辨率
((ISimpleMarker3DSymbol)markerSymbol).Style = esriSimple3DMarkerStyle.esriS3DMSSphere;
((ISimpleMarker3DSymbol)markerSymbol).ResolutionQuality = 1.0;
//markerSymbol的颜色和大小
IRgbColor color = new RgbColorClass();
color.Red = 255;
color.Green = 0;
color.Blue = 0;
markerSymbol.Size = 5;
markerSymbol.Color = color as IColor;
IElement pElement = new MarkerElementClass();
((IMarkerElement)pElement).Symbol = markerSymbol;
pElement.Geometry = pointCollection.Point[i];
pGraphicsContainer.AddElement(pElement, 0);
}
DataBoard dataBoard = new DataBoard("Position", dataTable,this,pointCollection.PointCount);
dataBoard.Show();
m_form.setButton_miShowTime(false);
}
public void HighLight(int row)
{
DataOperator dataoperator = new DataOperator(m_map);
IMarkerSymbol markerSymbol = new SimpleMarker3DSymbolClass();
//markerSymbol的类型和分辨率
((ISimpleMarker3DSymbol)markerSymbol).Style = esriSimple3DMarkerStyle.esriS3DMSSphere;
((ISimpleMarker3DSymbol)markerSymbol).ResolutionQuality = 1.0;
//markerSymbol的颜色和大小
IRgbColor color = new RgbColorClass();
color.Red = 250;
color.Green = 230;
color.Blue = 20;
markerSymbol.Size = 8;
markerSymbol.Color = color as IColor;
// 将showElement对象赋予markerSymbol的属性
IElement showElement = new MarkerElementClass();
((IMarkerElement)showElement).Symbol = markerSymbol;
showElement.Geometry = pointCollection.Point[row];
//在绘制前,清楚图像容器内的所有Elements
pGraphicsContainer.DeleteAllElements();//通过name删除
//为了使点在上面,先显示polygon
IGeometry polygon = pointCollection as IGeometry;
IPolygonElement polygonElement = new PolygonElementClass();
IElement polyElement = polygonElement as IElement;
polyElement.Geometry = polygon;
pGraphicsContainer.AddElement((IElement)polygonElement, 0);
//绘制高亮显示的点
pGraphicsContainer.AddElement((IElement)showElement, 0);
//重新绘制除了高亮点外的构造点
for (int i = 0; (i < pointCollection.PointCount); i++)
{
if (i != row)
{
IRgbColor color3 = new RgbColorClass(); //如果出现重复 将函数独立出来
color3.Red = 255;
color3.Green = 0;
color3.Blue = 0;
markerSymbol.Size = 5;
markerSymbol.Color = color3 ;
IElement pElement = new MarkerElementClass();
((IMarkerElement)pElement).Symbol = markerSymbol;
pElement.Geometry = pointCollection.Point[i];
pGraphicsContainer.AddElement(pElement, 0);
/*IElement pElement=new MarkerElementClass();
pElement.Geometry = pointCollection.Point[i];
pGraphicsContainer.AddElement(pElement, 0);*/
}
}
m_form.axMapControl1.ActiveView.Refresh();//partialrefresh
}
public void Update(double newvalue, int row, int column)//x,y一起修改
{
IPoint ipoint = (IPoint)pointCollection.Point[row];
switch (column)
{
case 0:
break;
case 1:
ipoint.X = newvalue;
break;
case 2:
ipoint.Y = newvalue;
break;
}
//对于pointCollection进行修改
pointCollection.UpdatePoint(row, ipoint);
//清空图像容器
pGraphicsContainer.DeleteAllElements();
IGeometry polygon = pointCollection as IGeometry;
IPolygonElement polygonElement = new PolygonElementClass();
IElement polyElement = polygonElement as IElement;
polyElement.Geometry = polygon;
pGraphicsContainer.AddElement((IElement)polygonElement, 0);
m_form.axMapControl1.ActiveView.Refresh();
for (int i = 0; i < pointCollection.PointCount; i++)
{
IMarkerSymbol markerSymbol = new SimpleMarker3DSymbolClass();
//markerSymbol的类型和分辨率
((ISimpleMarker3DSymbol)markerSymbol).Style = esriSimple3DMarkerStyle.esriS3DMSSphere;
((ISimpleMarker3DSymbol)markerSymbol).ResolutionQuality = 1.0;
//markerSymbol的颜色和大小
IRgbColor color = new RgbColorClass();
color.Red = 255;
color.Green = 0;
color.Blue = 0;
markerSymbol.Size = 5;
markerSymbol.Color = color as IColor;
IElement pElement = new MarkerElementClass();
((IMarkerElement)pElement).Symbol = markerSymbol;
pElement.Geometry = pointCollection.Point[i];
pGraphicsContainer.AddElement(pElement, 0);
/*IElement pElement=new MarkerElementClass();
pElement.Geometry = pointCollection.Point[i];
pGraphicsContainer.AddElement(pElement, 0);*/
}
m_form.axMapControl1.ActiveView.Refresh();
}
public void EndShow()
{
pGraphicsContainer.DeleteAllElements();
IGeometry polygon = pointCollection as IGeometry;
IPolygonElement polygonElement = new PolygonElementClass();
IElement polyElement = polygonElement as IElement;
polyElement.Geometry = polygon;
pGraphicsContainer.AddElement((IElement)polygonElement, 0);
m_form.axMapControl1.ActiveView.Refresh();
}
}
}