Arcgis engine 指定图层对要素进行创建、删除等操作
Arcgis engine 指定图层创建点要素
在指定的图层上创建一个点要素,点要素的位置是通过X,Y坐标指定的,下面是具体的注释 。其中 和IFeatureClassWrite接口有关的代码不要好像也可以实现这个功能,这里是直接通过IFeature添加要素的,不是通过IRow.
The IFeatureClassWrite interface provides low-level write access to feature class data. Any associated object behavior is not triggered. In general, IFeatureClassWrite should only be used when implementing custom features that bypass IRow::Store.
pLayer = this.axMapControl1.get_Layer(i);//所要加的层 IFeatureLayer pFeatureLyr = pLayer as IFeatureLayer;//将ILayer转换为IFeaturelayer,为了对图层上的要素进行编辑
IFeatureClass pFeatCls = pFeatureLyr.FeatureClass;//定义一个要素集合,并获取图层的要素集合
IFeatureClassWrite fr = (IFeatureClassWrite)pFeatCls;//定义一个实现新增要素的接口实例,并该实例作用于当前图层的要素集
IWorkspaceEdit w = (pFeatCls as IDataset).Workspace as IWorkspaceEdit;//定义一个工作编辑工作空间,用于开启前图层的编辑状态
IFeature f;//定义一个IFeature实例,用于添加到当前图层上
w.StartEditing(true);//开启编辑状态
w.StartEditOperation();//开启编辑操作
IPoint p;//定义一个点,用来作为IFeature实例的形状属性,即shape属性
//下面是设置点的坐标和参考系
p = new PointClass();
p.SpatialReference = this.axMapControl1.SpatialReference;
p.X = ;
p.Y = ; //将IPoint设置为IFeature的shape属性时,需要通过中间接口IGeometry转换
IGeometry peo;
peo = p;
f = pFeatCls.CreateFeature();//实例化IFeature对象, 这样IFeature对象就具有当前图层上要素的字段信息
f.Shape = peo;//设置IFeature对象的形状属性
f.set_Value(, "house1");//设置IFeature对象的索引是3的字段值
f.Store();//保存IFeature对象
fr.WriteFeature(f);//将IFeature对象,添加到当前图层上
w.StopEditOperation();//停止编辑操作
w.StopEditing(true);//关闭编辑状态,并保存修改
this.axMapControl1.Refresh();//刷新地图
删除指定图层的全部要素
private void DeleteAll()
{
ILayer pLayer = getLayerByName(axMapControl1, "Train");
//getLayerByName()方法为自定义函数,获取名称为“Train”的图层
IFeatureLayer pFeatureLyr = pLayer as IFeatureLayer;//将ILayer转换为IFeaturelayer,为了对图层上的要素进行编辑
IFeatureClass pFeatCls = pFeatureLyr.FeatureClass;//定义一个要素集合,并获取图层的要素集合
ITable pTable = (ITable)pFeatCls;
pTable.DeleteSearchedRows(null);
axMapControl1.ActiveView.Refresh();
}
arcengine创建要素类、图层的方法
对图层的创建除了可以参考下面的代码,也可以参考本博客的这篇文章: shp图层创建。
/// <summary>
/// 创建要素类
/// </summary>
/// <param name="pObject">IWorkspace或者IFeatureDataset对象</param>
/// <param name="pName">要素类名称</param>
/// <param name="pSpatialReference">空间参考</param>
/// <param name="pFeatureType">要素类型</param>
/// <param name="pGeometryType">几何类型</param>
/// <param name="pFields">字段集</param>
/// <param name="pUidClsId">CLSID值</param>
/// <param name="pUidClsExt">EXTCLSID值</param>
/// <param name="pConfigWord">配置信息关键词</param>
/// <returns>返回IFeatureClass</returns>
public static IFeatureClass CreateFeatureClass(object pObject, string pName, ISpatialReference pSpatialReference, esriFeatureType pFeatureType,
esriGeometryType pGeometryType, IFields pFields, UID pUidClsId, UID pUidClsExt, string pConfigWord)
{
#region 错误检测
if (pObject == null)
{
throw (new Exception("[pObject] 不能为空!"));
}
if (!((pObject is IFeatureWorkspace) || (pObject is IFeatureDataset)))
{
throw (new Exception("[pObject] 必须为IFeatureWorkspace 或者 IFeatureDataset"));
}
if (pName.Length == )
{
throw (new Exception("[pName] 不能为空!"));
}
if ((pObject is IWorkspace) && (pSpatialReference == null))
{
throw (new Exception("[pSpatialReference] 不能为空(对于单独的要素类)"));
}
#endregion // pUidClsID字段为空时 if (pUidClsId == null)
{
pUidClsId = new UIDClass();
switch (pFeatureType)
{
case (esriFeatureType.esriFTSimple):
if (pGeometryType == esriGeometryType.esriGeometryLine)
pGeometryType = esriGeometryType.esriGeometryPolyline;
pUidClsId.Value = "{52353152-891A-11D0-BEC6-00805F7C4268}";
break;
case (esriFeatureType.esriFTSimpleJunction):
pGeometryType = esriGeometryType.esriGeometryPoint;
pUidClsId.Value = "{CEE8D6B8-55FE-11D1-AE55-0000F80372B4}";
break;
case (esriFeatureType.esriFTComplexJunction):
pUidClsId.Value = "{DF9D71F4-DA32-11D1-AEBA-0000F80372B4}";
break;
case (esriFeatureType.esriFTSimpleEdge):
pGeometryType = esriGeometryType.esriGeometryPolyline;
pUidClsId.Value = "{E7031C90-55FE-11D1-AE55-0000F80372B4}";
break;
case (esriFeatureType.esriFTComplexEdge):
pGeometryType = esriGeometryType.esriGeometryPolyline;
pUidClsId.Value = "{A30E8A2A-C50B-11D1-AEA9-0000F80372B4}";
break;
case (esriFeatureType.esriFTAnnotation):
pGeometryType = esriGeometryType.esriGeometryPolygon;
pUidClsId.Value = "{E3676993-C682-11D2-8A2A-006097AFF44E}";
break;
case (esriFeatureType.esriFTDimension):
pGeometryType = esriGeometryType.esriGeometryPolygon;
pUidClsId.Value = "{496764FC-E0C9-11D3-80CE-00C04F601565}";
break;
}
} //pUidClsExt字段为空时
if (pUidClsExt == null)
{
switch (pFeatureType)
{
case esriFeatureType.esriFTAnnotation:
pUidClsExt = new UIDClass();
pUidClsExt.Value = "{24429589-D711-11D2-9F41-00C04F6BC6A5}";
break;
case esriFeatureType.esriFTDimension:
pUidClsExt = new UIDClass();
pUidClsExt.Value = "{48F935E2-DA66-11D3-80CE-00C04F601565}";
break;
}
} //字段集合为空时
if (pFields == null)
{
//实倒化字段集合对象
pFields = new FieldsClass();
IFieldsEdit tFieldsEdit = (IFieldsEdit)pFields; //创建几何对象字段定义
IGeometryDef tGeometryDef = new GeometryDefClass();
IGeometryDefEdit tGeometryDefEdit = tGeometryDef as IGeometryDefEdit; //指定几何对象字段属性值
tGeometryDefEdit.GeometryType_2 = pGeometryType;
tGeometryDefEdit.GridCount_2 = ;
tGeometryDefEdit.set_GridSize(, );
if (pObject is IWorkspace)
{
tGeometryDefEdit.SpatialReference_2 = pSpatialReference;
} //创建OID字段
IField fieldOID = new FieldClass();
IFieldEdit fieldEditOID = fieldOID as IFieldEdit;
fieldEditOID.Name_2 = "OBJECTID";
fieldEditOID.AliasName_2 = "OBJECTID";
fieldEditOID.Type_2 = esriFieldType.esriFieldTypeOID;
tFieldsEdit.AddField(fieldOID); //创建几何字段
IField fieldShape = new FieldClass();
IFieldEdit fieldEditShape = fieldShape as IFieldEdit;
fieldEditShape.Name_2 = "SHAPE";
fieldEditShape.AliasName_2 = "SHAPE";
fieldEditShape.Type_2 = esriFieldType.esriFieldTypeGeometry;
fieldEditShape.GeometryDef_2 = tGeometryDef;
tFieldsEdit.AddField(fieldShape);
} //几何对象字段名称
string strShapeFieldName = "";
for (int i = ; i < pFields.FieldCount; i++)
{
if (pFields.get_Field(i).Type == esriFieldType.esriFieldTypeGeometry)
{
strShapeFieldName = pFields.get_Field(i).Name;
break;
}
} if (strShapeFieldName.Length == )
{
throw (new Exception("字段集中找不到几何对象定义"));
} IFeatureClass tFeatureClass = null;
if (pObject is IWorkspace)
{
//创建独立的FeatureClass
IWorkspace tWorkspace = pObject as IWorkspace;
IFeatureWorkspace tFeatureWorkspace = tWorkspace as IFeatureWorkspace;
tFeatureClass = tFeatureWorkspace.CreateFeatureClass(pName, pFields, pUidClsId, pUidClsExt, pFeatureType, strShapeFieldName, pConfigWord);
}
else if (pObject is IFeatureDataset)
{
//在要素集中创建FeatureClass
IFeatureDataset tFeatureDataset = (IFeatureDataset)pObject;
tFeatureClass = tFeatureDataset.CreateFeatureClass(pName, pFields, pUidClsId, pUidClsExt, pFeatureType, strShapeFieldName, pConfigWord);
} return tFeatureClass;
}
创建图层、要素类
图层中批量添加点要素
创建好要素图层后,需要对要素图层添加要素。本部分以点要素的添加为例进行讲解。
/// <summary>
/// 点坐标 结构体
/// </summary>
public class PointXY
{
public double dX;
public double dY;
} /// <summary>
/// 建立 ESRI中的 点类型 并 将其转化为基类接口 IGeometry
/// </summary>
/// <param name="point">点坐标 结构体</param>
/// <returns></returns>
public IGeometry CreatePoint(PointXY point)
{
IPoint pPoint = new PointClass();
pPoint.X = point.dX;
pPoint.Y = point.dY;
IGeometry pGeometry = pPoint as IGeometry;
return pGeometry;
} /// <summary>
/// 批量加入 点坐标 结构体
/// </summary>
/// <param name="pLayer">点图层</param>
/// <param name="pointCol">泛型集合【点坐标 结构体】</param>
/// <returns></returns>
public bool AddPointsToLayer(ILayer pLayer, List<PointXY> pointCol)
{
IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
if (pFeatureLayer == null)
{
MessageBox.Show(pLayer.Name + "不是矢量图层!");
return false;
}
//
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
if (pFeatureClass.ShapeType != esriGeometryType.esriGeometryPoint)
{
System.Windows.Forms.MessageBox.Show(pLayer.Name + "不是点图层!");
return false;
}
//
IFeatureCursor pFeatureCursor = pFeatureClass.Insert(true);
IFeatureBuffer pFeatureBuffer = null;
foreach(PointXY one in pointCol)
{
pFeatureBuffer = pFeatureClass.CreateFeatureBuffer();
IFeature pNewFeature = pFeatureBuffer as IFeature;
pNewFeature.Shape = BuildPoint(one);
//
pFeatureCursor.InsertFeature(pFeatureBuffer);
}
pFeatureCursor.Flush(); return true;
}
批量添加点要素
参考文章
小马哥淡定 ,Arcgis engine 指定图层创建点要素
Arcgis engine 指定图层对要素进行创建、删除等操作的更多相关文章
- 二叉排序树(BST)创建,删除,查找操作
binary search tree,中文翻译为二叉搜索树.二叉查找树或者二叉排序树.简称为BST 一:二叉搜索树的定义 他的定义与树的定义是类似的,也是一个递归的定义: 1.要么是一棵空树 2.如果 ...
- 利用ArcGIS Engine、VS .NET和Windows控件开发GIS应用
Dixon 原文 用ArcGIS Engine.VS .NET和Windows控件开发GIS应用 此过程说明适合那些使用.NET建立和部署应用的开发者,它描述了使用ArcGIS控件建立和部署 ...
- C#,ArcGIS Engine开发入门教程
C#,ArcGIS Engine开发入门教程 转自:http://blog.csdn.net/yanleigis/article/details/2233674 目录(?)[+] 五实现 一 加载A ...
- [转] arcgis Engine创建shp图层
小生 原文 arcgis Engine创建shp图层 以创建点图层为例.首先要得到保存文件的地址. SaveFileDialog saveFileDialog = new SaveFileDialog ...
- ArcGIS Desktop和Engine中对点要素图层Graduated Symbols渲染的实现 Rotation Symbol (转)
摘要 ArcGIS中,对于要素图层的渲染,支持按照要素字段的值渲染要素的大小,其中Graduated Symbols可以对大小进行分级渲染.在个人开发系统的过程中,也可以用来美化数据显 ...
- ArcGIS Engine环境下创建自定义的ArcToolbox Geoprocessing工具
在上一篇日志中介绍了自己通过几何的方法合并断开的线要素的ArcGIS插件式的应用程序.但是后来考虑到插件式的程序的配置和使用比较繁琐,也没有比较好的错误处理机制,于是我就把之前的程序封装成一个类似于A ...
- 《ArcGIS Engine+C#实例开发教程》第七讲 图层符号选择器的实现2
原文:<ArcGIS Engine+C#实例开发教程>第七讲 图层符号选择器的实现2 摘要:在第七讲 图层符号选择器的实现的第一阶段中,我们完成了符号选择器窗体的创建与调用.在第二阶段中, ...
- ArcGIS Engine中如何获取Map中已经选择的要素呢(转)
ArcGIS Engine中如何获取Map中已经选择的要素呢 1.使用IEnumFeturea对象获取map中的FeatureSelection,该方法可以获取所有图层的选择要素.IMap中的Fe ...
- ArcGIS Engine效率探究——要素的添加和删除、属性的读取和更新
ArcGIS Engine效率探究——要素的添加和删除.属性的读取和更新 来自:http://blog.csdn.net/freewaywalker/article/details/23703863 ...
随机推荐
- Android 学习笔记进阶14之像素操作
在我们玩的游戏中我们会经常见到一些图像的特效,比如半透明等效果.要实现这种半透明效果其实并不难,需要我们懂得图像像素的操作. 不要怕,其实在Android中Bitmap为我们提供了操作像素的基本方法. ...
- android图像处理系列之五-- 给图片添加边框(中)
前面一篇讲到给图片加边框的方式,只能给图片加一些有规则的边框,如果想加一些比较精美的效果,就有点麻烦了.下面就给出解决这个问题的思路. 思路是:一些比较精美的花边图片我们是很难用代码控制,就目前本人水 ...
- 智课雅思词汇---三、aud和auto和bene是什么意思
智课雅思词汇---三.aud和auto和bene是什么意思 一.总结 一句话总结:aud:听 auto:自己,self bene:good,well 1.anthropo是什么意思? anthropo ...
- 2.CURL命令
转自:https://blog.csdn.net/ligang2585116/article/details/46548617 curl是一种命令行工具,作用是发出网络请求,然后得到和提取数据,显示在 ...
- 59.node的serve-favicon中间件的使用
转自:https://www.zhi-jie.net/node-serve-favicon-use/ 有一个名称为serve-favicon的中间件,可以用于请求网页的favicon图标.譬如如下的使 ...
- PDF Adobe Acrobat 9 简体中文专业版(打印店内部的软件)(你懂的!)
福利 => 每天都推送 欢迎大家,关注微信扫码并加入我的4个微信公众号: 大数据躺过的坑 Java从入门到架构师 人工智能躺过的坑 Java全栈大联盟 ...
- OpenCV —— 写入AVI视频文件
打开视频文件,对每一帧进行极坐标变换,然后将转换生成的图像序列写入视频文件中 #include "cv.h" #include "highgui.h" int ...
- 使用maven的tomcat:run进行web项目热部署
近期又又一次看了一下maven的东西,事实上主要是由于去了解Jenkins,后期或许会补充jenkins的博文. 怎么在eclipse里面创建maven webproject,这边就不介绍了,參见:h ...
- Pig源代码分析: 简析运行计划的生成
摘要 本文通过跟代码的方式,分析从输入一批Pig-latin到输出物理运行计划(与launcher引擎有关,通常是MR运行计划.也能够是Spark RDD的运行算子)的总体流程. 不会详细涉及AST怎 ...
- SQL中实现千分位的语句
传递一个sql的小知识,现成的语句,在工作流的表单域中很实用. 数字或字符串转成千分位 ) 字符串转换成数值 )