美文网首页
ArcEngine效率探索--添加要素

ArcEngine效率探索--添加要素

作者: 子页 | 来源:发表于2018-06-29 15:54 被阅读0次

    版本

    ArcGis 10.1,C#

    ArcEngine中添加要素的方式有两种

    一种使用IFeatureClass.CreateFeature和IFeature.Store方法实现
    一种使用IFeatureClass.CreateFeatureBuffer的insert cursor来实现
    插入大量数据时用insert cursor的效率高于CreateFeature和Store方法。

    使用CreateFeature和Store创建要素

    public static 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();
    }
    

    使用insert cursor创建要素

    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)
            {
                // Set the feature buffer's shape and insert it.
                featureBuffer.Shape = geometry;
                insertCursor.InsertFeature(featureBuffer);
            }
     
            // Flush the buffer to the geodatabase.
            insertCursor.Flush();
        }
    }
    

    相关文章

      网友评论

          本文标题:ArcEngine效率探索--添加要素

          本文链接:https://www.haomeiwen.com/subject/bayayftx.html