基于C#的ArcEngine二次开发教程(13):点、线、面要素的绘制

您所在的位置:网站首页 ae如何画线 基于C#的ArcEngine二次开发教程(13):点、线、面要素的绘制

基于C#的ArcEngine二次开发教程(13):点、线、面要素的绘制

2024-07-01 15:07| 来源: 网络整理| 查看: 265

目录

1 利用ArcMap绘制点、线和面的操作

1.1 绘图工具,绘制临时要素

1.2 在矢量图层中直接添加要素的方法

2 以Element的方式加入点要素

2.1 IGraphicsContainer

2.2 IElement

 2.3 IGeometry

 2.4 点元素添加实现源码

3 以Element形式添加线元素

3.1 IPolyline接口

​3.2 IPointCollection接口

3.3 源码实现

4 以Element形式添加线元素

4.1 PolygonClass

 4.2 源码实现

5 以矢量要素的形式添加点线面

5.1 点要素的添加

5.2 线要素的添加

5.3 面要素添加

1 利用ArcMap绘制点、线和面的操作 1.1 绘图工具,绘制临时要素

添加Element图形元素,它仅保存在内存中,相当于以Map为画布,进行绘制的;软件关闭之后就会消失

1.2 在矢量图层中直接添加要素的方法

在矢量图层中添加Feature要素,添加到矢量数据,并永久保存到硬盘中

 

2 以Element的方式加入点要素 2.1 IGraphicsContainer

图形容器接口,用于存放临时的点线面要素数据

接口介绍见缓冲区分析博文

2.2 IElement

以下三个类均对该接口进行了实现

 2.3 IGeometry

类Point对其进行了实现

 同时也实现了IPoint类,满足接口跳转的条件

 2.4 点元素添加实现源码

(1)定义全局变量

IPoint pt; IElement gele;

(2)添加axMapControl1_OnMouseDown事件,用于记录鼠标点下的位置坐标

  private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)         {             pt = new PointClass();             pt.X = e.mapX;             pt.Y = e.mapY;             gele = new MarkerElementClass();             gele.Geometry = pt as IGeometry;             //生成线         }

(3)添加点要素

  private void 添加点元素ToolStripMenuItem_Click(object sender, EventArgs e)         {             IGraphicsContainer igc = axMapControl1.Map as IGraphicsContainer;              igc.AddElement(gele, 0);             axMapControl1.Refresh();         } 3 以Element形式添加线元素 3.1 IPolyline接口 3.2 IPointCollection接口

 通过接口IPolyline定义的Polyline类对象可以在接口IGeomtry、和IPointCollection之间跳转

3.3 源码实现

(1)定义全局变量

IPointCollection lineCollect;//添加点集合; IPoint linePts;

(2)Form1_Load创建IPointCollection接口实例对象

private void Form1_Load(object sender, EventArgs e)         {                    lineCollect = new PolylineClass();//添加线元素         }

(3)添加axMapControl1_OnMouseDown事件,用于记录鼠标点下的位置坐标

 private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)         {             //生成线             linePts = new PointClass();             linePts.X = e.mapX;             linePts.Y = e.mapY;             //object a = Type.Missing;             lineCollect.AddPoint(linePts);//添加多个点到点集合中         }

(4)添加线要素

private void 添加线元素ToolStripMenuItem_Click(object sender, EventArgs e)         {             IGraphicsContainer igc = axMapControl1.Map as IGraphicsContainer;              IElement lineEle = new LineElementClass();             IPolyline pline = new PolylineClass();             pline = lineCollect as IPolyline;               lineEle.Geometry = pline as IGeometry;             igc.AddElement(lineEle, 0);             axMapControl1.Refresh();         } 4 以Element形式添加线元素 4.1 PolygonClass

继承接口

 4.2 源码实现

(1)定义全局变量

  //面         IPointCollection ploygonCollect;//添加点集合;         IPoint ploygonPts;

(2)Form1_Load创建IPointCollection接口实例对象

  private void Form1_Load(object sender, EventArgs e)         {                         ploygonCollect = new PolygonClass();         }

(3)添加axMapControl1_OnMouseDown事件,用于记录鼠标点下的位置坐标

  private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)         {               //生成面             ploygonPts = new PointClass();             ploygonPts.X = e.mapX;             ploygonPts.Y = e.mapY;             //object a = Type.Missing;             ploygonCollect.AddPoint(ploygonPts);           }

(4)添加面要素

  private void 添加面元素ToolStripMenuItem_Click(object sender, EventArgs e)         {             IGraphicsContainer igc = axMapControl1.Map as IGraphicsContainer;              IElement polygonele = new PolygonElementClass();             IPolygon polyg = new PolygonClass();             polyg = ploygonCollect as IPolygon;             polygonele.Geometry = polyg as IGeometry;             igc.AddElement(polygonele, 0);             axMapControl1.Refresh();         } 5 以矢量要素的形式添加点线面 5.1 点要素的添加 private void 添加点到矢量图层ToolStripMenuItem_Click(object sender, EventArgs e)         {             IFeatureLayer felyer = axMapControl1.get_Layer(0) as IFeatureLayer;             IFeatureClass feclass = felyer.FeatureClass;             IFeature fea = feclass.CreateFeature();//点要素的创建             fea.Shape = pt as IGeometry;             fea.Store();//点要素的存储             axMapControl1.Refresh();         } 5.2 线要素的添加 private void 添加线到矢量图层ToolStripMenuItem_Click(object sender, EventArgs e)         {             IFeatureLayer felyer = axMapControl1.get_Layer(0) as IFeatureLayer;             IFeatureClass feclass = felyer.FeatureClass;             IFeature fea = feclass.CreateFeature();             IPolyline pline = new PolylineClass();             pline = lineCollect as IPolyline;             fea.Shape = pline as IGeometry;             fea.Store();             axMapControl1.Refresh();         } 5.3 面要素添加         private void 添加面到矢量图层ToolStripMenuItem_Click(object sender, EventArgs e)         {             IFeatureLayer felyer = axMapControl1.get_Layer(0) as IFeatureLayer;             IFeatureClass feclass = felyer.FeatureClass;             IFeature fea = feclass.CreateFeature();             IPolygon polygon = new PolygonClass();             polygon = ploygonCollect as IPolygon;             fea.Shape = polygon as IGeometry;             fea.Store();             axMapControl1.Refresh(); }



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3