SDE資料編輯過程中異常中斷後產生錯誤的處理

來源:互聯網
上載者:User

      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<br />// acceptable (but not necessarily optimal) values.<br />public void RebuildSpatialIndex(IFeatureClass featureClass, Double gridOneSize,<br /> Double gridTwoSize, Double gridThreeSize)<br />{<br /> // Get an enumerator for indexes based on the shape field.<br /> IIndexes indexes = featureClass.Indexes;<br /> String shapeFieldName = featureClass.ShapeFieldName;<br /> IEnumIndex enumIndex = indexes.FindIndexesByFieldName(shapeFieldName);<br /> enumIndex.Reset();</p><p> // Get the index based on the shape field (should only be one) and delete it.<br /> IIndex index = enumIndex.Next();<br /> if (index != null)<br /> {<br /> featureClass.DeleteIndex(index);<br /> }</p><p> // Clone the shape field from the feature class.<br /> int shapeFieldIndex = featureClass.FindField(shapeFieldName);<br /> IFields fields = featureClass.Fields;<br /> IField sourceField = fields.get_Field(shapeFieldIndex);<br /> IClone sourceFieldClone = (IClone)sourceField;<br /> IClone targetFieldClone = sourceFieldClone.Clone();<br /> IField targetField = (IField)targetFieldClone;</p><p> // Open the geometry definition from the cloned field and modify it.<br /> IGeometryDef geometryDef = targetField.GeometryDef;<br /> IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;<br /> geometryDefEdit.GridCount_2 = 3;<br /> geometryDefEdit.set_GridSize(0, gridOneSize);<br /> geometryDefEdit.set_GridSize(1, gridTwoSize);<br /> geometryDefEdit.set_GridSize(2, gridThreeSize);</p><p> // Create a spatial index and set the required attributes.<br /> IIndex newIndex = new IndexClass();<br /> IIndexEdit newIndexEdit = (IIndexEdit)newIndex;<br /> newIndexEdit.Name_2 = shapeFieldName + "_Index";<br /> newIndexEdit.IsAscending_2 = true;<br /> newIndexEdit.IsUnique_2 = false;</p><p> // Create a fields collection and assign it to the new index.<br /> IFields newIndexFields = new FieldsClass();<br /> IFieldsEdit newIndexFieldsEdit = (IFieldsEdit)newIndexFields;<br /> newIndexFieldsEdit.AddField(targetField);<br /> newIndexEdit.Fields_2 = newIndexFields;</p><p> // Add the spatial index back into the feature class.<br /> featureClass.AddIndex(newIndex);<br />}</p><p>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.