SDE数据编辑过程中异常中断后产生错误的处理

      ArcSDE经常在数据导入或编辑过程中中断,其间有人为因素(调试中断)也有非人为因素(断网),中断后的直接恶果就是程序再次执行出错。错误号是-2147216556,错误解释是 FDO_E_OBJECTCLASS_REQUIRES_AN_EDIT_SESSION。

      通常让写程序的人很郁闷,因为在程序中已经调用了StartEdit等,程序已经开始session编辑过程,确还报上述的错误。而事实上上是ArcSDE的空间索引已经在中断过程中被破坏了,需要重新计算。在我们对数据进行编辑的过程中,新添加记录或修改记录都会自动地去修改当前的要素类的索引,如果程序这时出错,空间索引的修改过程是无法完成的。导致我们在重新编辑数据的过程中无意中使用了无效的空间索引,在编辑过程中就会报-2147216556错误。

      解决方法就是重新计算空间索引。重新计算空间索引在ArcGIS有很多种方法,可以用ArcCatalog属性页中Index项下操作索引编辑或重新计算功能。或者是采用GP下的重新计算索引工具。甚至也可以用代码来修改,在ArcObjects的帮助中,有如下的方法可以参考:

// 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 = 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); }

你可能感兴趣的:(session,String,null,delete,Parameters,工具)