ArcEngine创建要素

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">来源:ArcEngine帮助文档</span>


Summary

  This topic explains how to create features in a geodatabase feature class. Two methods are shown, one that creates an individual feature using the IFeatureClass.CreateFeature and IFeature.Store methods, and one that uses an insert cursor to execute a bulk load.

About creating features
The functionality available for feature creation is dependent on the following:
  • The license level the code runs on and the type of geodatabase it runs against.
  • The type of features that are being created—whether they are simple features, network features, created in a topology, and so on. For example, an ArcGIS for Desktop Standard or Advanced license is required to create features in the following:
    • Geometric network or topology
    • Dimension feature class
    • Annotation feature class
    • ArcSDE geodatabase, whether at the personal, workgroup, or enterprise level
The following are two primary ways to create features in the geodatabase: 
The following are the main differences between the two primary ways to create features in a geodatabase:
  • Calling IFeature.Store results in all object behavior being triggered. This includes—but is not limited to—behavior specific to network or annotation features and features that participate in a topology, as well as events, such as those from the IObjectClassEvents interface.
  • Insert cursors are used to bulk insert features in the geodatabase. Using an insert cursor and a feature buffer offers significantly faster performance for simple data loading and creation than creating features and storing them. The one catch is that when using the IFeatureCursor.InsertFeature method, complex behavior and the triggering of events is not guaranteed.
  • The IObjectClassInfo and IWorkspaceEditControl interfaces can be used to enforce the calling of IFeature.Store by insert cursors, but this negates any performance advantages they offer.

If more than one simple feature is being created, always use an insert cursor for performance considerations.

   
The following code example demonstrates how to use the IFeatureClass.CreateFeature method and IFeature.Store to create a feature in a feature class containing pipes:

[C#]
public static void CreateFeature(IFeatureClass featureClass, IPolyline polyline)
{
    // Build the feature.
    IFeature feature = featureClass.CreateFeature();
    feature.Shape = polyline;

    // Apply the appropriate subtype to the feature.
    ISubtypes subtypes = (ISubtypes)featureClass;
    IRowSubtypes rowSubtypes = (IRowSubtypes)feature;
    if (subtypes.HasSubtype)
    {
        // In this example, the value of 3 represents the polymer vinyl chloride (PVC) subtype.
        rowSubtypes.SubtypeCode = 3;
    }

    // Initialize any default values the feature has.
    rowSubtypes.InitDefaultValues();

    // Update the value on a string field that indicates who installed the feature.
    int contractorFieldIndex = featureClass.FindField("CONTRACTOR");
    feature.set_Value(contractorFieldIndex, "K Johnston");

    // Commit the new feature to the geodatabase.
    feature.Store();
}

Using insert cursors

public static void InsertFeaturesUsingCursor(IFeatureClass featureClass, List <IGeometry > geometryList)
 {
    using(ComReleaser comReleaser = new ComReleaser())   
       {
        // Create a feature buffer.
        IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
        comReleaser.ManageLifetime(featureBuffer);
        // Create an insert cursor.
        IFeatureCursor insertCursor = featureClass.Insert(true);
        comReleaser.ManageLifetime(insertCursor);
        // All of the features to be created are classified as Primary Highways.
        int typeFieldIndex = featureClass.FindField("TYPE");
        featureBuffer.set_Value(typeFieldIndex, "Primary Highway");
        foreach (IGeometry geometry in geometryList)        
  <span style="white-space:pre">	</span>{
            // Set the feature buffer's shape and insert it.
            featureBuffer.Shape = geometry;
            insertCursor.InsertFeature(featureBuffer);       
        }
        // Flush the buffer to the geodatabase.       
<span style="white-space:pre">	</span> insertCursor.Flush();
    }}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值