C# 使用 ArcGIS API 创建多边形要素
这段代码是用于在地图控件上创建多边形要素的函数。以下是对该函数的解释:
private void createPolygonToolStripMenuItem_Click(object sender, EventArgs e)
{
// 创建多边形要素的顶点坐标
IPoint point1 = new PointClass();
point1.PutCoords(10, 20);
IPoint point2 = new PointClass();
point2.PutCoords(40, 50);
IPoint point3 = new PointClass();
point3.PutCoords(60, 40);
IPoint point4 = new PointClass();
point4.PutCoords(50, 10);
// 创建多边形要素的边线
ILine pLine = new LineClass();
ISegmentCollection pPath = new PathClass();
object o = Type.Missing;
// 添加边线到路径
pLine.PutCoords(point1, point2);
pPath.AddSegment(pLine as ISegment, ref o, ref o);
pLine = new LineClass();
pLine.PutCoords(point2, point3);
pPath.AddSegment(pLine as ISegment, ref o, ref o);
pLine = new LineClass();
pLine.PutCoords(point3, point4);
pPath.AddSegment(pLine as ISegment, ref o, ref o);
// 创建多边形要素的环
ISegmentCollection pRing = new RingClass();
for (int i = 0; i < pPath.SegmentCount; i++)
{
pRing.AddSegment(pPath.get_Segment(i) as ISegment);
}
IRing pRing2 = pRing as IRing;
pRing2.Close();
// 创建多边形要素并添加到几何要素集合
IGeometryCollection pPolygon = new PolygonClass();
pPolygon.AddGeometry(pRing2 as IGeometry, ref o, ref o);
IGeometry polygon = new PolygonClass();
polygon = pPolygon as IGeometry;
// 将多边形要素添加到地图控件中的图层
addFeature('polygon', polygon);
// 设置地图控件的显示范围为多边形的边界框
this.axMapControl1.Extent = polygon.Envelope;
// 刷新地图控件显示
this.axMapControl1.Refresh();
}
该函数的功能是在地图控件上创建一个由四个顶点组成的多边形要素,并将其添加到地图中的图层中。该多边形要素的边线通过给定的顶点坐标构建,并通过路径和环的方式进行组织。最后,函数会根据多边形的边界框设置地图控件的显示范围,并刷新地图控件以显示新添加的多边形要素。
原文地址: https://www.cveoy.top/t/topic/bKhx 著作权归作者所有。请勿转载和采集!