ArcEngine创建IFeature的三种方法

原文链接:https://blog.csdn.net/kone0611/article/details/78530514

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

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);

使用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();
}

转载于:https://www.cnblogs.com/King2019Blog/p/11319539.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值