AE实现在地图中画要素

it2024-07-11  43

1.画线draw仅保存在内存,通过添加IGraphicsContainer接口中的AddElement方法来进行添加画点线面。

​ 步骤:1.使用IPoint生成点,point.X=e.MapX;point.Y=e.MapY;

​ 2.添加要素:使用IGraphicsContainer接口中的AddElement方法来进行添加。与点不同的是,线和面都是需要创建点集合。

2.创建要素,先要获得要素图层(相当于编辑要素中创建),通过使用IFeatureClass中的creatFeature方法来实现创建要素。

​ 步骤: ​ 1) Create the feature ​ 2) Create the geometry for the feature ​ 3) Store the geometry in the feature 存储 ​ 4) Store the feature

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Geodatabase; namespace drow { public partial class Form1 : Form { //生成点的全局变量 IPoint pt; IElement el; IGraphicsContainer gra; //生成线的全局变量 IPointCollection linepcol; IPoint linpt; //生成面的全局变量 IPoint polygonpt; IPointCollection polyctn; public Form1() { ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop); InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { gra = axMapControl1.Map as IGraphicsContainer; linepcol = new PolylineClass(); polyctn = new PolygonClass(); } //添加点 private void button1_Click(object sender, EventArgs e) { gra.AddElement(el,0); axMapControl1.Refresh(); } //axMapControl1_OnMouseDown事件就是在Mapcontrol中点击时会触发的事件 private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e) { //生成点 pt = new PointClass(); pt.X = e.mapX; pt.Y = e.mapY; el = new MarkerElementClass(); //el.Geometry = pt as IGeometry; el.Geometry = pt; //生成线 linpt = new PointClass(); linpt.X = e.mapX; linpt.Y = e.mapY; object a = Type.Missing; linepcol.AddPoint(linpt,ref a,ref a); //生成面 polygonpt = new PointClass(); polygonpt.X = e.mapX; polygonpt.Y = e.mapY; polyctn.AddPoint(polygonpt, ref a, ref a); } //添加线 private void button2_Click(object sender, EventArgs e) { IElement lineele = new LineElementClass(); IPolyline pline = new PolylineClass(); pline = linepcol as IPolyline; lineele.Geometry = pline as IGeometry; gra.AddElement(lineele, 0); axMapControl1.Refresh(); } //添加面 private void button3_Click(object sender, EventArgs e) { IElement polyele = new PolygonElementClass(); IPolygon pogy = new PolygonClass(); pogy = polyctn as IPolygon; polyele.Geometry = pogy as IGeometry; gra.AddElement(polyele,0); axMapControl1.Refresh(); } /*创建要素的步骤: 1) Create the feature 2) Create the geometry for the feature 3) Store the geometry in the feature 存储 4) Store the feature */ //创建矢量图层编辑画点 private void button4_Click(object sender, EventArgs e) { //1 IFeatureLayer flyr = axMapControl1.get_Layer(0) as IFeatureLayer; IFeatureClass feaclass = flyr.FeatureClass; IFeature fea = feaclass.CreateFeature(); fea.Shape = pt as IGeometry; fea.Store(); axMapControl1.Refresh(); } //创建矢量图层编辑画线 private void button5_Click(object sender, EventArgs e) { IFeatureLayer flyr = axMapControl1.get_Layer(0) as IFeatureLayer; IFeatureClass feaclass = flyr.FeatureClass; IFeature fea = feaclass.CreateFeature(); fea.Shape = linepcol as IGeometry;//linepcol为点集 fea.Store(); axMapControl1.Refresh(); } //创建矢量图层编辑画面 private void button6_Click(object sender, EventArgs e) { IFeatureLayer flyr = axMapControl1.get_Layer(0) as IFeatureLayer; IFeatureClass feaclass = flyr.FeatureClass; IFeature fea = feaclass.CreateFeature(); fea.Shape = polyctn as IGeometry;//polyctn为点集 fea.Store(); axMapControl1.Refresh(); } } }
最新回复(0)