ArcEngine创建IFeature的三种方法
来源:互联网 发布:海康威视网络配置设置 编辑:程序博客网 时间:2024/06/11 02:27
在ArcGIS Resouce Center中,ESRI介绍了两种创建Feature的方法(可以在本地的Geodatabase和sde的featureclass)
一、
IFeatureClass.CreateFeature,在这种方法最后需要加上IFeature.Store去提交创建的要素,本人认为这种方法相比下面一种方法更好些,因为Store的方法能够直接提交修改并在数据库中看到,不会因为其他复杂的操作影响数据入库。下面是在SDE库中创建IFeature的代码给大家参考一下:
IAoInitialize m_AoInitializa = new AoInitializeClass();esriLicenseStatus pEsriLicenseStatus=m_AoInitializa.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);IPropertySet propSet = new PropertySetClass();propSet.SetProperty("SERVER", "192.168.1.143");propSet.SetProperty("INSTANCE", "5151");propSet.SetProperty("USER", "myTestUser");propSet.SetProperty("PASSWORD", "123456");propSet.SetProperty("VERSION", "SDE.DEFAULT");IWorkspaceFactory pwf = new SdeWorkspaceFactoryClass();IFeatureWorkspace pFeatureWorkspace= (IFeatureWorkspace)(pwf.Open(propSet, 0)) ;IFeatureClassfeaClass=pFeatureWorkspace.OpenFeatureClass("要打开的Featureclass名字"); IFeature feature = feaClass.CreateFeature();feature.Shape=IGeometry;//(这里的IGeometry可以是IPolygon,IPolyline,IPoint)int fieldindex = feature.Fields.FindField("字段名");feature.set_Value(fieldindex, "字段值");feature.Store();
二、
IFeatureClass.CreateFeatureBuffer,这个方法采用插入游标(Insert Cursors)的方法,在创建简单数据的时候效率会比第一种方法更快些,但是在ESRI的官网上提到使用IFeatureCursor.InsertFeature方法时,复杂的操作和各种事件的触发不能够保证。根据自己实际操作的心得,有时候会出现数据创建延时,明明代码已经通过了,但数据库中的数据要过很久才能显示出来,甚至有时候都显示不出来。这个客户肯定接受不了这种没有保证的数据创建。还有一点,在使用SDE库时,这种方法只适用于没有注册版本的dateset或featureclass(这个仅仅是在我的程序中出现过这种问题,仅供参考),下面为代码(打开SDE的部分就不重复了)
IFeatureCursor feaCursor = feaClass.Insert(true);IFeatureBuffer feaBuffer = feaClass.CreateFeatureBuffer();feaBuffer.Shape = IGeometry;//(这里的IGeometry可以是IPolygon,IPolyline,IPoint)int fieldindex = feaBuffer.Fields.FindField("字段名");if (fieldindex >= 0){ feaBuffer.set_Value(fieldindex, "字段值" );}feaCursor.InsertFeature(feaBuffer);
经过一位网友的帮助,以上的文章有不足的地方,就是IFeatureClass.CreateFeatureBuffer在featureclass中插入一条记录,在本文中feaCursor.InsertFeature(feaBuffer)之后加上feaCrusor.Fulsh()将创建的记录输入到数据库中,而且在面对大数据量插入的时候用IFeatureClass.CreateFeatureBuffer()效率比IFeatureClass.CreateFeature高,详细可以参见以下网址:LINK,这里面有详细介绍.
三、
使用IFeatureClassWriter接口
public void DrawPoint(ILayer pLayer,double X,double Y) { IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; IFeatureClassWrite fr = pFeatureClass as IFeatureClassWrite; IFeature pFeature; IPoint pPoint; //pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); pFeature = pFeatureClass.CreateFeature(); pPoint = new PointClass(); pPoint.PutCoords(X, Y); pFeature.Shape = pPoint; fr.WriteFeature(pFeature); pWorkspaceEdit.StopEditOperation(); }
- ArcEngine创建IFeature的三种方法
- AO创建IFeature的两种方法
- ArcEngine开启编辑功能的三种方法
- ArcEngine开发中关于获取IFeature对象Pfeature坐标的说明
- arcengine创建要素类、图层的方法
- ArcEngine保存mxd的方法
- 创建IXMLDOMDocument对象的三种方法
- 创建Connection对象的三种方法
- Java创建对象的三种方法
- 创建字符设备的三种方法
- 链表创建的三种方法
- widowsSDK创建对话框的三种方法
- 创建字符设备的三种方法
- 创建线程的三种方法
- 创建DirectDraw对象的三种方法
- 创建字符设备的三种方法
- java创建数组的三种方法
- oracle创建数据库的三种方法
- Apache 与 Nginx 比较
- 静态库与动态库
- LeetCode-714:Best Time to Buy and Sell Stock with Transaction Fee (带有抛售费用的股票最大利润) -- medium
- php判断图片是否显示完全的方式---图片损坏
- LeetCode 86. Partition List
- ArcEngine创建IFeature的三种方法
- dede常用数据库相关命令
- Quartz两个定时任务的配置
- 从 HTTP 到 HTTPS 再到 HSTS
- LeetCode 206. Reverse Linked List && 92. Reverse Linked List II
- 阿里云 CDN HTTPS 最佳实践——OCSP Stapling(四)
- 报错:1130-host ... is not allowed to connect to this MySql server 开放mysql远程连接 不使用localhost
- VS2010+Qt4调试时监视窗口部分类型变量只显示地址不显示值
- 关于MySQL授权