Rebuild Spatial Index

// Passing zero values for all three double parameters recalculates the spatial index with
// acceptable (but not necessarily optimal) values.public void RebuildSpatialIndex(IFeatureClass featureClass, Double gridOneSize, Double gridTwoSize, Double gridThreeSize){ // Get an enumerator for indexes based on the shape field. IIndexes indexes = featureClass.Indexes; String shapeFieldName = featureClass.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) { featureClass.DeleteIndex(index); } // Clone the shape field from the feature class. int shapeFieldIndex = featureClass.FindField(shapeFieldName); IFields fields = featureClass.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 IndexClass(); 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 FieldsClass(); IFieldsEdit newIndexFieldsEdit = (IFieldsEdit)newIndexFields; newIndexFieldsEdit.AddField(targetField); newIndexEdit.Fields_2 = newIndexFields; // Add the spatial index back into the feature class. featureClass.AddIndex(newIndex);} [VB.NET] ' Passing zero values for all three double parameters recalculates the spatial index with' acceptable (but not necessarily optimal) values.Public Sub RebuildSpatialIndex(ByVal featureClass As IFeatureClass, ByVal gridOneSize As DoubleByVal gridTwoSize AsDoubleByVal gridThreeSize As Double' Get an enumerator for indexes based on the shape field. Dim indexes As IIndexes = featureClass.Indexes Dim shapeFieldName As String = featureClass.ShapeFieldName Dim enumIndex As IEnumIndex = indexes.FindIndexesByFieldName(shapeFieldName) enumIndex.Reset() ' Get the index based on the shape field (should only be one) and delete it. Dim index As IIndex = enumIndex.Next() If Not index Is Nothing Then featureClass.DeleteIndex(index) End If ' Clone the shape field from the feature class. Dim shapeFieldIndex As Integer = featureClass.FindField(shapeFieldName) Dimfields As IFields = featureClass.Fields Dim sourceField As IField = fields.Field(shapeFieldIndex) Dim sourceFieldClone AsIClone = CType(sourceField, IClone) Dim targetFieldClone As IClone = sourceFieldClone.Clone() Dim targetField As IField =CType(targetFieldClone, IField) ' Open the geometry definition from the cloned field and modify it. Dim geometryDef AsIGeometryDef = targetField.GeometryDef Dim geometryDefEdit As IGeometryDefEdit = CType(geometryDef, IGeometryDefEdit) geometryDefEdit.GridCount_2 = 3 geometryDefEdit.GridSize_2(0) = gridOneSize geometryDefEdit.GridSize_2(1) = gridTwoSize geometryDefEdit.GridSize_2(2) = gridThreeSize ' Create a spatial index and set the required attributes. Dim newIndex As IIndex = New IndexClass() Dim newIndexEdit As IIndexEdit = CType(newIndex, IIndexEdit) 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. Dim newIndexFields As IFields = New FieldsClass() Dim newIndexFieldsEdit AsIFieldsEdit = CType(newIndexFields, IFieldsEdit) newIndexFieldsEdit.AddField(targetField) newIndexEdit.Fields_2 = newIndexFields ' Add the spatial index back into the feature class. featureClass.AddIndex(newIndex) End Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值