[ArcEngine]IFeatureBuffer使用

 1 public static void LoadOnlyModeInsert(IFeatureClass featureClass, List < IGeometry >
 2     geometryList)
 3 {
 4     // Cast the feature class to the IFeatureClassLoad interface.
 5     IFeatureClassLoad featureClassLoad = (IFeatureClassLoad)featureClass;
 6 
 7     // Acquire an exclusive schema lock for the class.
 8     ISchemaLock schemaLock = (ISchemaLock)featureClass;
 9     try
10     {
11         schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
12 
13         // Enable load-only mode on the feature class.
14         featureClassLoad.LoadOnlyMode = true;
15         using(ComReleaser comReleaser = new ComReleaser())
16         {
17             // Create the feature buffer.
18             IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
19             comReleaser.ManageLifetime(featureBuffer);
20 
21             // Create an insert cursor.
22             IFeatureCursor insertCursor = featureClass.Insert(true);
23             comReleaser.ManageLifetime(insertCursor);
24 
25             // All of the features to be created are classified as Primary Highways.
26             int typeFieldIndex = featureClass.FindField("TYPE");
27             featureBuffer.set_Value(typeFieldIndex, "Primary Highway");
28 
29             foreach (IGeometry geometry in geometryList)
30             {
31                 // Set the feature buffer's shape and insert it.
32                 featureBuffer.Shape = geometry;
33                 insertCursor.InsertFeature(featureBuffer);
34             }
35 
36             // Flush the buffer to the geodatabase.
37             insertCursor.Flush();
38         }
39     }
40     catch (Exception)
41     {
42         // Handle the failure in a way appropriate to the application.
43     }
44     finally
45     {
46         // Disable load-only mode on the feature class.
47         featureClassLoad.LoadOnlyMode = false;
48 
49         // Demote the exclusive schema lock to a shared lock.
50         schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
51     }
52 }

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值