1、前言

ArcEngine中,创建要素一般分为两部分,即:设置空间信息、设置属性信息。下面给出实现代码。

2、定义实体类

首先在ArcMap中创建一个文件,其属性字段如下表所示:

字段名称 字段类型
FID 整型
Shape 几何
Longitude(经度) 双精度
Latitude(纬度) 双精度
SchoolName(学校名称) 文本
SchoolType(学校类型) 文本

根据该属性表创建一个实体类——SchoolModel,代码如下:

using System.ComponentModel;namespace WindowsFormsApplication1
{public class SchoolModel{[Category("只读属性")][Description("FID")][ReadOnly(true)]public int FID { get; set; }[Category("只读属性")][Description("Shape")][ReadOnly(true)]public string Shape { get; set; }[Category("只读属性")][Description("经度")][ReadOnly(true)]public double Longitude { get; set; }[Category("只读属性")][Description("纬度")][ReadOnly(true)]public double Latitude { get; set; }[Category("可编辑属性")][Description("名称")][ReadOnly(false)]public string SchoolName { get; set; }[Category("可编辑属性")][Description("类型")][ReadOnly(false)][TypeConverter(typeof(SchoolTypeItem))]public string SchoolType { get; set; }}public class SchoolTypeItem : StringConverter{public override bool GetStandardValuesSupported(ITypeDescriptorContext context){return true;}public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context){return new StandardValuesCollection(new string[] { "幼儿园", "小学", "初中", "高中", "大学" });}public override bool GetStandardValuesExclusive(ITypeDescriptorContext context){return true;}}
}

3、创建要素

搭建一个如下图所示的界面:


代码如下所示:

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using System;
using System.Windows.Forms;namespace WindowsFormsApplication1
{public partial class MainForm : Form{private IWorkspaceEdit pWorkspaceEdit;private IFeature pFeature;// 构造函数public MainForm(){InitializeComponent();axMapControl1.LoadMxFile(@"C:\Users\DSF\Desktop\data\无标题.mxd");axMapControl1.Extent = axMapControl1.FullExtent;btnStartEditing.Enabled = true;btnStopEditing.Enabled = false;}// 开始编辑private void btnStartEditing_Click(object sender, EventArgs e){IFeatureLayer pFeatureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;IDataset pDataset = pFeatureClass as IDataset;IWorkspace pWorkspace = pDataset.Workspace;pWorkspaceEdit = pWorkspace as IWorkspaceEdit;pWorkspaceEdit.StartEditing(true);btnStartEditing.Enabled = false;btnStopEditing.Enabled = true;}// 结束编辑private void btnStopEditing_Click(object sender, EventArgs e){pWorkspaceEdit.StopEditing(true);pWorkspaceEdit = null;pFeature = null;// 清除选择axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);axMapControl1.Map.ClearSelection();axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);// 设置控件btnStartEditing.Enabled = true;btnStopEditing.Enabled = false;prgFeatureAttributes.SelectedObject = null;}// 点击地图创建要素private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e){if (pWorkspaceEdit != null){IPoint pPoint = new ESRI.ArcGIS.Geometry.Point();pPoint.PutCoords(e.mapX, e.mapY);// 获取字段索引IFeatureLayer pFeatureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;IFields pFields = pFeatureClass.Fields;int fieldIndex_Longitude = pFields.FindField("Longitude");int fieldIndex_Latitude = pFields.FindField("Latitude");// 创建新要素pFeature = pFeatureClass.CreateFeature();pFeature.Shape = pPoint;pFeature.set_Value(fieldIndex_Longitude, pPoint.X);pFeature.set_Value(fieldIndex_Latitude, pPoint.Y);pFeature.Store();// 清除选择axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);axMapControl1.Map.ClearSelection();axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);// 选中该要素IQueryFilter pQueryFilter = new QueryFilter();pQueryFilter.WhereClause = "FID=" + pFeature.OID.ToString();IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection;pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);axMapControl1.ActiveView.Refresh();// 创建实体类SchoolModel schoolModel = new SchoolModel{FID = pFeature.OID,Shape = "点",Longitude = Math.Round(pPoint.X, 3),Latitude = Math.Round(pPoint.Y, 3),SchoolName = "",SchoolType = ""};prgFeatureAttributes.SelectedObject = schoolModel;}}// 设置要素属性值private void prgFeatureAttributes_PropertyValueChanged(object s, PropertyValueChangedEventArgs e){if (pFeature != null){int fieldIndex = pFeature.Fields.FindField(e.ChangedItem.Label);pFeature.set_Value(fieldIndex, e.ChangedItem.Value);pFeature.Store();}}}
}

运行结果如下图所示:


打开ArcMap,如下图所示,可以发现刚刚创建的要素可以正常显示。

ArcEngine编辑模块——创建要素相关推荐

  1. ArcEngine编辑模块——批量删除要素

    1.前言 在ArcEngine中,删除要素的方法有很多,你可以使用IFeatureCursor或ITable查询出部分要素然后依次删除.但这两个接口只能针对单个图层的要素进行删除,而在编辑状态下,我们 ...

  2. ArcEngine编辑模块——移动单个要素的实现方法

    1.前言 在ArcEngine中,移动单个点.线.面要素主要使用以下三个接口: IMovePointFeedback IMoveLineFeedback IMovePolygonFeedback 需要 ...

  3. ArcEngine编辑模块——批量旋转要素

    1.前言 在ArcEngine中,要素的批量旋转可以使用IFeatureEdit实现,下面给出实现代码. 2.旋转要素 2.1.主界面代码 using ESRI.ArcGIS.Controls; us ...

  4. ArcEngine编辑模块——将线段按距离、按比例分割成N条线段

    1.前言 前面一篇博客介绍了如何按距离或按比例将1条线段分成2条线段的方法,核心就是利用IFeatureEdit接口的Split方法进行分割.但就像之前说的,该方法只适用于将1条线段分成2条线段,如果 ...

  5. ArcEngine编辑模块——将线段按距离、按比例分割成两部分

    1.前言 在ArcEngine中,线段的分割主要使用IFeatureEdit接口的Split方法实现.需要注意的是:该方法只能将1条线段按距离或按比例分割成 2条线段,关于如何将1条线段分成n条线段( ...

  6. AE二次开发中几个功能速成归纳(符号设计器、创建要素、图形编辑、属性表编辑、缓冲区分析)...

    /** 实习课上讲进阶功能所用文档,因为赶时间从网上抄抄改改,凑合能用,记录一下以备个人后用.** -------------------------------------------------- ...

  7. QGIS绘制一张地图——创建和编辑绘制线要素、由线要素生成面要素、面要素的编辑

    前言 我们以描绘北京市市区案例来演示这部分功能.步骤大致如下: 1.按照市区分区的分界线来绘制线要素. 2.根据所绘线要素生成面要素. 3.对生成的面要素做整理编辑. 待绘制底图如图所示: 一.创建和 ...

  8. gis里创建要素面板怎么打开_gis、mike学习

    自己制作一条河流,赋值,模拟河流流动: gis制图: 1.将gis页面缩放到合适的比例: 2.编辑器-开始编辑(在创建要素中选择线)-直线段(或断面弧段): 3.编辑器-构造点(每1m一个断面): 4 ...

  9. gis里创建要素面板怎么打开_【从零开始学GIS】ArcGIS中的绘图基本操作(二)

    大家好,我是肝教程肝到熊猫眼的三三. 本系列教程的发布,受到了很多同学的鼓励,大家在后台或微信上表达出对教程的喜爱,这便是更新教程的最大动力. 上回教程讲解了"GIS基本操作".& ...

最新文章

  1. 【组队学习】【26期】图神经网络
  2. hdu 2514 Another Eight Puzzle
  3. stm32关于.o的错误
  4. 利物浦大学comp313课程第一节课
  5. 一个有趣的python排序模块:bisect
  6. mysql自动获取时间列_mysql自动获取时间日期的方法
  7. [Flink]Flink DataStream API 概览
  8. Random walk 和 random walk with Restart理解
  9. Linux centos6 命令行配置网络连接
  10. (尚硅谷)JavaWeb新版教程08-QQZone项目的实现
  11. 超星的Pdg/Pdz转带书签目录Pdf的好方法
  12. 随机森林模型调参方法
  13. Ubuntu:安装yarn
  14. Android 选择文件(调用系统文件管理器)
  15. 跳马周游c++_汉诺塔,n皇后,跳马问题汇总
  16. TOP100summit2017:微博如何做到1小时增加一千台服务器应对鹿晗恋情带来的流量暴增
  17. Mezzanine入门
  18. error pulling image configuration:XXX net/http: TLS handshake timeout
  19. 强制双休!传腾讯光子调整加班机制,21 点前必须离开工位
  20. 【科普篇】云存储与传统存储

热门文章

  1. android 判断U盘是否挂载
  2. 电气simulink常用模块_建筑电气制图图形符号之二,火灾自动报警符号,赶快收藏吧...
  3. 单片机IO直接驱动段式LCD详细说明+代码
  4. oracle中include,impdpexpdp的content和include选项
  5. WINDOWS 安装XGBoost GPU版本最新简易方法
  6. uva188 完美哈希题解
  7. 数据挖掘之stacking模型融合(以阿里妈妈广告点击率预估比赛为例)
  8. SpringBoot 整合【Mybatis-Plus实现分页查询】
  9. 鸿图之下服务器维护10月25,更新公告丨《鸿图之下》12月30日维护更新预告
  10. 创建模板只有从空白html文档开始创建,word 2019如何创建空白文档和模板文档