Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am writing an application that takes data from an Excel Spreadsheet and loads it into an ArcSDE feature class. The Feature class is editable within ArcMap, but I am having trouble inserting a feature with the code.

My code does the following

  1. Starts an edit session.

    Public Sub StartEditing(fctarget)
    
    Dim peditor As IEditor
    Dim pID    As New UID
    Dim pFeatureLayer As IFeatureLayer
    Dim pDataset As IDataset
    Dim pMap   As IMap
    Dim pmxdoc As IMxDocument
    Dim LayerCount As Integer
    Set pmxdoc = Application.Document
    Set pMap = pmxdoc.FocusMap
    pID = "esriEditor.Editor"
    Set peditor = Application.FindExtensionByCLSID(pID)
    
    If peditor.EditState = esriStateEditing Then Exit Sub
    
    'Start editing the workspace of teh feature layer
    Set pDataset = fctarget
    MsgBox "Editing: " & pDataset.BrowseName
    peditor.StartEditing pDataset.Workspace
    
    peditor.StartOperation
    
    End Sub
    
  2. Load the data (if it is a new record, the following code runs)

      If pfeatLayer Is Nothing Then    'if it does not exist - it is new
    
      'Insert a new record and add new attribute information
      Set pFeatInsertBuf.Shape = pFeat.Shape
      Debug.Print pFeatInsertBuf.Shape.envelope.XMax
      xField = pFeatInsertBuf.Fields.FindFieldByAliasName("ORIG_X")
      yField = pFeatInsertBuf.Fields.FindFieldByAliasName("ORIG_Y")
    
      pFeatInsertBuf.Value(xField) = pFeat.extent.XMax
      pFeatInsertBuf.Value(yField) = pFeat.extent.YMax
    
        'Update the attributes
      For C = 1 To NumberOfFields
            If IsNull(pExcelApp.Cells(r, C).Value) Then
                pFeatInsertBuf.Value(C).Value = ""
            Else
                pFeatInsertBuf.Value(C) = pExcelApp.Cells(r, C).Value
            End If
     Next C
     Debug.Print pFeatInsertBuf.Fields.FieldCount
     Debug.Print pFeatInsertBuf.Value(2)
     Debug.Print pFeatInsertCur.Fields.FieldCount
     'store the record
     pFeatInsertCur.InsertFeature pFeatInsertBuf ' #######INSERT THE FEATURE######
     Print #1, "Row number " & r & ": " & "inserted"
     Debug.Print "Row number " & r & ": " & "inserted"
    
  3. When it has gone through the rest of the spreadsheet, the stop editing process is called and the editor session is closed.

    Public Sub stopSaveEdits(step As String)
    
    Dim lngCityDevRefVal As Long
    
    Dim peditor As IEditor
    Dim pID    As New UID
    Dim lngSave As Integer
    Dim pMap   As IMap
    Dim pmxdoc As IMxDocument
    ' get the current map document and create and editor object
    Set pmxdoc = ThisDocument
    Set pMap = pmxdoc.FocusMap
    pID = "esriEditor.Editor"
    Set peditor = Application.FindExtensionByCLSID(pID)
    'step = "Save"
    If peditor.EditState = esriStateEditing Then
        'lngSave = MsgBox("Do you want to save?", vbYesNo, "Save data")
        If step = "Save" Then
            peditor.StopOperation "Saving..."
            Exit Sub
        ElseIf step = "SaveStop" Then
            peditor.StopOperation "Saving..."
    
            If peditor.HasEdits = True Then
                peditor.StopEditing True
                'MsgBox "Changes have been saved"
    
                Exit Sub
            End If
        Else
            peditor.AbortOperation
            'peditor.StopOperation "Saving..."
            peditor.StopEditing False
            MsgBox "Changes have not been saved"
        End If
    End If
    
    End Sub
    

The problem is that the new feature never gets inserted, even though i have specified to do it. Has anyone got any ideas on what I am doing wrong?

Note - Using ArcGIS Desktop 9.3.1, ArcSDE is 9.2

Thanks!

share|improve this question
2  
How did you create pFeatInsertCur? If you create with "useBuffering" options yes, then , you need to write IFeatureCursor::Flush method at last. –  Darksanta Apr 26 '13 at 8:17
    
Your code is not showing the full story, how is the FeatureBuffer created? –  Hornbydd Apr 29 '13 at 13:13
    
@Darksanta, the pFeatInsertCur was set to true, I set it to false (and in the mean time upgraded ArcSDE to 9.3.1) and it now works. –  Halil Siddique May 1 '13 at 10:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.