[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 }

 

你可能感兴趣的:(ArcEngine)