• [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 }
  • 相关阅读:
    编程爱好者论坛第六次编程比赛题目
    google china code jam round2 div1 1000分题
    ogl2dlibsdl cvs repository @ cosoft
    偶尔也提一个游戏点子:宇宙碰撞
    今天看到一些笑话...
    google china code jam入围赛的一个题
    用Regular expression寻找源代码中的汉字字符串
    生成函数理论初步
    Komodo 的中文支持
    “豪华版”的USB延长线
  • 原文地址:https://www.cnblogs.com/yhlx125/p/3678996.html
Copyright © 2020-2023  润新知