当前位置: 首页>>代码示例>>C#>>正文


C# IFeatureClass.AddIndex方法代码示例

本文整理汇总了C#中IFeatureClass.AddIndex方法的典型用法代码示例。如果您正苦于以下问题:C# IFeatureClass.AddIndex方法的具体用法?C# IFeatureClass.AddIndex怎么用?C# IFeatureClass.AddIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFeatureClass的用法示例。


在下文中一共展示了IFeatureClass.AddIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddFieldIndex

        //---------------------------------------------------------------------
        // CHANGED: CR13 (Export features performance)
        // Add a new attribute index to a feature class.
        /// <summary>
        /// Adds an attribute index to a field in a feature class.
        /// </summary>
        /// <param name="featureClass">The feature class.</param>
        /// <param name="indexName">Name of the index.</param>
        /// <param name="fieldName">Name of the field.</param>
        public void AddFieldIndex(IFeatureClass featureClass, String indexName, String fieldName)
        {
            // Ensure the feature class contains the specified field.
            int fieldIndex = featureClass.FindField(fieldName);
            if (fieldIndex == -1)
                return;

            // Get the specified field from the feature class.
            IFields featureClassFields = featureClass.Fields;
            IField field = featureClassFields.get_Field(fieldIndex);

            // Create a fields collection and add the specified field to it.
            IFields fields = new FieldsClass();
            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
            fieldsEdit.FieldCount_2 = 1;
            fieldsEdit.set_Field(0, field);

            //Create an index and cast to the IIndexEdit interface.
            IIndex index = new IndexClass();
            IIndexEdit indexEdit = (IIndexEdit)index;

            // Set the index's properties, including the associated fields.
            indexEdit.Fields_2 = fields;
            indexEdit.IsAscending_2 = false;
            indexEdit.IsUnique_2 = false;
            indexEdit.Name_2 = indexName;

            // Attempt to acquire an exclusive schema lock on the feature class.
            ISchemaLock schemaLock = (ISchemaLock)featureClass;
            try
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                featureClass.AddIndex(index);
            }
            catch (COMException comExc)
            {
                // Handle this in a way appropriate to your application.
                Console.WriteLine("A COM Exception was thrown: {0}", comExc.Message);
            }
            finally
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        }
开发者ID:HabitatFramework,项目名称:HLUTool,代码行数:53,代码来源:HluArcMapExtension.cs

示例2: createSpatialIndex

        public static void createSpatialIndex(IFeatureClass fc, double gridOneSize = 0.0, double gridTwoSize = 0.0, double gridThreeSize = 0.0)
        {
            String shapeFieldName = fc.ShapeFieldName;

            // Clone the shape field from the feature class.
            int shapeFieldIndex = fc.FindField(shapeFieldName);
            IFields fields = fc.Fields;
            IField sourceField = fields.get_Field(shapeFieldIndex);
            IClone sourceFieldClone = (IClone)sourceField;
            IClone targetFieldClone = sourceFieldClone.Clone();
            IField targetField = (IField)targetFieldClone;

            // Open the geometry definition from the cloned field and modify it.
            IGeometryDef geometryDef = targetField.GeometryDef;
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
            if (gridTwoSize > 0.0)
            {
                geometryDefEdit.GridCount_2 = 1;
                geometryDefEdit.set_GridSize(0, gridOneSize);
            }
            if (gridTwoSize > 0.0)
            {
                geometryDefEdit.GridCount_2 = 2;
                geometryDefEdit.set_GridSize(1, gridTwoSize);
            }
            if (gridThreeSize > 0.0)
            {
                geometryDefEdit.GridCount_2 = 3;
                geometryDefEdit.set_GridSize(2, gridThreeSize);
            }

            // Create a spatial index and set the required attributes.
            IIndex newIndex = new IndexClass();
            IIndexEdit newIndexEdit = (IIndexEdit)newIndex;
            newIndexEdit.Name_2 = shapeFieldName + "_Indx";

            // Create a fields collection and assign it to the new index.
            IFields newIndexFields = new FieldsClass();
            IFieldsEdit newIndexFieldsEdit = (IFieldsEdit)newIndexFields;
            newIndexFieldsEdit.AddField(targetField);
            newIndexEdit.Fields_2 = newIndexFields;

            // Add the spatial index back into the feature class.
            fc.AddIndex(newIndex);
        }
开发者ID:EsriCanada,项目名称:TechTrek_Idol_2016,代码行数:45,代码来源:GPHelperFunctions.cs


注:本文中的IFeatureClass.AddIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。