Beispiel #1
0
        public bool DeleteSpatialIndex(IFeatureClass featureClass)
        {
            bool        result      = true;
            ISchemaLock pSchemaLock = featureClass as ISchemaLock;

            try
            {
                pSchemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                IIndexes   indexes        = featureClass.Indexes;
                String     shapeFieldName = featureClass.ShapeFieldName;
                IEnumIndex enumIndex      = indexes.FindIndexesByFieldName(shapeFieldName);
                enumIndex.Reset();
                IIndex index = enumIndex.Next();
                if (index != null)
                {
                    featureClass.DeleteIndex(index);
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.ToString();
                result       = false;
            }
            finally
            {
                pSchemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
            return(result);
        }
        public static void dropSpatialIndex(IFeatureClass fc)
        {
            //Delete the spatial index
            IIndexes   indexes        = fc.Indexes;
            String     shapeFieldName = fc.ShapeFieldName;
            IEnumIndex enumIndex      = indexes.FindIndexesByFieldName(shapeFieldName);

            enumIndex.Reset();

            // Get the index based on the shape field (should only be one) and delete it.
            IIndex index = enumIndex.Next();

            if (index != null)
            {
                fc.DeleteIndex(index);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 重建要素类空间索引
        /// </summary>
        /// <param name="pFeatureClass"></param>
        /// <param name="gridOneSize"></param>
        /// <param name="gridTwoSize"></param>
        /// <param name="gridThreeSize"></param>
        /// <returns></returns>
        public bool RebuildSpatialIndex(IFeatureClass pFeatureClass, Double gridOneSize = 0, Double gridTwoSize = 0, Double gridThreeSize = 0)
        {
            ISchemaLock pSchemaLock = pFeatureClass as ISchemaLock;

            try
            {
                pSchemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                // Get an enumerator for indexes based on the shape field.
                IIndexes   indexes        = pFeatureClass.Indexes;
                String     shapeFieldName = pFeatureClass.ShapeFieldName;
                IEnumIndex enumIndex      = indexes.FindIndexesByFieldName(shapeFieldName);
                enumIndex.Reset();

                // Get the index based on the shape field (should only be one) and delete it.
                IIndex index = enumIndex.Next();
                if (index != null)
                {
                    pFeatureClass.DeleteIndex(index);
                }

                // Clone the shape field from the feature class.
                int     shapeFieldIndex  = pFeatureClass.FindField(shapeFieldName);
                IFields fields           = pFeatureClass.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;
                geometryDefEdit.GridCount_2 = 3;
                geometryDefEdit.set_GridSize(0, gridOneSize);
                geometryDefEdit.set_GridSize(1, gridTwoSize);
                geometryDefEdit.set_GridSize(2, gridThreeSize);

                // Create a spatial index and set the required attributes.
                IIndex     newIndex     = new Index();
                IIndexEdit newIndexEdit = (IIndexEdit)newIndex;
                newIndexEdit.Name_2        = String.Concat(shapeFieldName, "_Index");
                newIndexEdit.IsAscending_2 = true;
                newIndexEdit.IsUnique_2    = false;

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

                // Add the spatial index back into the feature class.
                pFeatureClass.AddIndex(newIndex);
                return(true);
            }
            catch
            {
                return(false);
            }
            finally
            {
                pSchemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        }