rfairhur24

.Net Update Cursors SDE Editing and Updating Editor

Discussion created by rfairhur24 on Nov 10, 2011
Latest reply on Nov 19, 2011 by rfairhur24
Three questions:

1) I am trying to create an add-in for distribution that edits features both inside and outside of an edit session while Desktop is open.  If I was designing this just for my own use I would know the way the add-in behaved and would generally know not to try to edit a workspace I do not have write access to, but I do not want to assume that about my users.  What is the best way to test that a workspace can be edited by a user?

2) SDE seems to always need an Edit session started for any of the editing code I have ever gotten to work, but geoprocessing tools work on SDE data without an edit session being started by the user.  I have tried using the IWorkSpaceEdit to determine if an edit session already exists and if it does not I begin an edit session in the code and wrap the actual edits in a StartOperation and StopOperation pair.  I do not seem to see this behavior with non-SDE feature classes (which do not use a edit session and just update the feature directly).

Below is my code.  It completes fine, but the Editor in ArcMap does not actually start an Edit session and if after it completes I try to manually start an Edit Session on an affected SDE feature class it says it is not editable until I click on the map somewhere.  So it seems that somehow I am not releasing the lock on the feature class.  I am using an Update cursor, which I know does not fire events like the store method on a search cursor, and I notice that I cannot flush the cursor within the Edit Operation without triggering an error.  But I would like to use the Update Cursor for speed.  Any ideas on what I can do to get the edits to complete in a way that allows the user to begin an edit session? 

      ' Assume I have a valid Feature Class assigned to the pFC variable
   Try
      Dim pFCursor As ESRI.ArcGIS.Geodatabase.IFeatureCursor = Nothing
      pFCursor = pFC.Update(Nothing, False) ' Create an UpdateCursor on FeatureClass
      Dim pFeat As ESRI.ArcGIS.Geodatabase.IFeature
      pFeat = pFCursor.NextFeature ' Get First Feature
      If pFeat Is Nothing Then
        MsgBox("No Route Features Selected!")
        Return
      End If

      Dim pDataset As ESRI.ArcGIS.Geodatabase.IDataset = pFC
      Dim IsVersion As Boolean = False
      If TypeOf pDataset Is ESRI.ArcGIS.Geodatabase.IVersionedObject Then
        IsVersion = True
      End If
      Dim workspace As ESRI.ArcGIS.Geodatabase.IWorkspace = pDataset.Workspace
      ' use IWorkspaceEdit
      Dim pWorkspaceEdit As ESRI.ArcGIS.Geodatabase.IWorkspaceEdit = workspace


      If IsVersion Then
        If Not pWorkspaceEdit.IsBeingEdited Then
          pWorkspaceEdit.StartEditing(True)
          If Not pWorkspaceEdit.IsBeingEdited Then
            MsgBox("Cannot start editing SDE Workspace")
            Return
          Else
            pWorkspaceEdit.StartEditOperation()
          End If
        Else
          pWorkspaceEdit.StartEditOperation()
        End If
      End If

      Dim i as Long = 0 ' Initialize a feature counter

      Do While Not pFeat Is Nothing

        ' do some kind of edit of the feature here

        pFCursor.UpdateFeature(pFeat) ' Update the cursor
        pFeat = pFCursor.NextFeature
        i = i + 1 ' Counter for features processed
        If i Mod 1000 = 0 Then ' flush edits after every 1,000 features
          If Not IsVersion Then
            pFCursor.Flush()
          End If
        End If
      Loop

      If Not IsVersion Then
        pFCursor.Flush() ' Final Flush of edits
      Else
        pWorkspaceEdit.StopEditOperation()
      End If
   Catch ex As Exception
     MsgBox(ex.ToString)
   End Try


3)  If an Edit session is started on the workspace, I want to be able to update the Editor dialogs, such as the feature coordinate dialog that can be accessed when a single feature is selected and its vertices are being edited.  I know that the Update cursor won't do this as it is processing the  features.  Is there a way to get the Editor to see the updates when the edits are finished?  Do I have to use a SearchCursor and the feature's store method to make that happen?

Thanks for any help.

Outcomes