Customer Service | Training | Contact Us
You are here: Home > User Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects Visual Basic for Application (VBA) forum

How to store updated feature?   Tao Li Nov 04, 2009
Re: How to store updated feature?   Paritosh Gupta Nov 04, 2009
Re: How to store updated feature?   Tao Li Nov 05, 2009
Re: How to store updated feature?   Paritosh Gupta Nov 05, 2009
Re: How to store updated feature?   Hailiang Shen Nov 06, 2009
Re: How to store updated feature?   Tao Li Nov 09, 2009
Report Inappropriate Content • Top • Print • Reply    
Subject How to store updated feature? 
Author Tao Li 
Date Nov 04, 2009 
Message I have assigned a new geometry to pFeature.Shape
and i want to store the changes
i am doing this with in edit session
i get automation error
at the line pFCursor.Updatefeature pfeature
I tried to use pFeature.Store instead, it says an edit operation is required.
what am i missin? 
 
Option Explicit

Public Sub EllipDetect()

Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pFLayer As IFeatureLayer
Dim pFClass As IFeatureClass
Dim pFCursor As IFeatureCursor
Dim pFeature As IFeature

Set pMxDoc = Application.Document
Set pMap = pMxDoc.FocusMap
Set pFLayer = pMap.Layer(0)
Set pFClass = pFLayer.FeatureClass
Set pFCursor = pFClass.Update(Nothing, False)

Dim logObject As Object
Set logObject = CreateObject("Scripting.FileSystemObject")
Dim txtStream As Object
Set txtStream = logObject.CreateTextFile("C:\Documents and Settings\TLI\Desktop\elliplog.txt")
'write gui for this part, use dlg
Dim txtString As String

Dim pGeom As IGeometry
Dim pSegColl As ISegmentCollection
Dim pSegCounter As Long
Dim pSegment As ISegment
Dim pToPoint As IPoint
Dim pFromPoint As IPoint
Dim pArcCenter As IPoint
Dim pISCCW As Boolean
Dim pEllipArc As IEllipticArc
Dim pCArc As ICircularArc
Dim SemiMajor As Double
Dim SemiMinor As Double
Dim MajMinRatio As Double
Dim pGeoColl As IGeometryCollection

Set pFeature = pFCursor.NextFeature
Do Until pFeature Is Nothing
    Set pSegColl = pFeature.ShapeCopy
    For pSegCounter = 0 To (pSegColl.SegmentCount - 1)
        Set pSegment = pSegColl.Segment(pSegCounter)
        If pSegment.GeometryType = esriGeometryEllipticArc Then
            Set pEllipArc = pSegment 'QI
            pEllipArc.GetAxes SemiMajor, SemiMinor, MajMinRatio
            If MajMinRatio < 0.9 Then 'This is tolerance
                txtString = pFeature.OID & " ## " & Str(pSegCounter) & "_Fix_by_Hand_"
                txtStream.WriteLine txtString
            Else
                Set pArcCenter = pEllipArc.CenterPoint
                Set pFromPoint = pEllipArc.FromPoint
                Set pToPoint = pEllipArc.ToPoint
                pISCCW = pEllipArc.IsCounterClockwise
                Set pCArc = New CircularArc
                pCArc.PutCoords pArcCenter, pFromPoint, pToPoint, pISCCW
                pSegColl.RemoveSegments pSegCounter, 1, False
                pSegColl.AddSegment pCArc
                pSegColl.SegmentsChanged
                Set pGeoColl = New Polyline
                pGeoColl.AddGeometryCollection pSegColl
                Set pFeature.Shape = pGeoColl
                Debug.Print pSegColl.SegmentCount & " ## " & pFeature.OID
            End If
        End If
    Next pSegCounter
    pFCursor.UpdateFeature pFeature
    Set pFeature = pFCursor.NextFeature
Loop
txtStream.Close

End Sub
 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: How to store updated feature? 
Author Paritosh Gupta 
Date Nov 04, 2009 
Message Hi Tao
You need to use IWorkSpaceEdit to start and stop edit operation. Following is your modified code: - 
 
Option Explicit

Public Sub EllipDetect()

Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pFLayer As IFeatureLayer
Dim pFClass As IFeatureClass
Dim pFCursor As IFeatureCursor
Dim pFeature As IFeature

Set pMxDoc = Application.Document
Set pMap = pMxDoc.FocusMap
Set pFLayer = pMap.Layer(0)
Set pFClass = pFLayer.FeatureClass
Set pFCursor = pFClass.Update(Nothing, False)

Dim logObject As Object
Set logObject = CreateObject("Scripting.FileSystemObject")
Dim txtStream As Object
Set txtStream = logObject.CreateTextFile("C:\Documents and Settings\TLI\Desktop\elliplog.txt")
'write gui for this part, use dlg
Dim txtString As String

Dim pGeom As IGeometry
Dim pSegColl As ISegmentCollection
Dim pSegCounter As Long
Dim pSegment As ISegment
Dim pToPoint As IPoint
Dim pFromPoint As IPoint
Dim pArcCenter As IPoint
Dim pISCCW As Boolean
Dim pEllipArc As IEllipticArc
Dim pCArc As ICircularArc
Dim SemiMajor As Double
Dim SemiMinor As Double
Dim MajMinRatio As Double
Dim pGeoColl As IGeometryCollection

Dim pDataSet as IDataSet
Set pDataSet = pFClass.FeatureDataSet
Dim pWorkSpace as IWorkSpace
Set pWorkSpace = pDataSet
Dim pWorkSpaceEdit as IWorkSpaceEdit
Set pWorkSpaceEdit = pWorkSpace 

Set pFeature = pFCursor.NextFeature
Do Until pFeature Is Nothing

    pWorkSpaceEdit.StartEditing True
    pWorkSpaceEdit.StartEditOperation

    Set pSegColl = pFeature.ShapeCopy
    For pSegCounter = 0 To (pSegColl.SegmentCount - 1)
        Set pSegment = pSegColl.Segment(pSegCounter)
        If pSegment.GeometryType = esriGeometryEllipticArc Then
            Set pEllipArc = pSegment 'QI
            pEllipArc.GetAxes SemiMajor, SemiMinor, MajMinRatio
            If MajMinRatio < 0.9 Then 'This is tolerance
                txtString = pFeature.OID & " ## " & Str(pSegCounter) & "_Fix_by_Hand_"
                txtStream.WriteLine txtString
            Else
                Set pArcCenter = pEllipArc.CenterPoint
                Set pFromPoint = pEllipArc.FromPoint
                Set pToPoint = pEllipArc.ToPoint
                pISCCW = pEllipArc.IsCounterClockwise
                Set pCArc = New CircularArc
                pCArc.PutCoords pArcCenter, pFromPoint, pToPoint, pISCCW
                pSegColl.RemoveSegments pSegCounter, 1, False
                pSegColl.AddSegment pCArc
                pSegColl.SegmentsChanged
                Set pGeoColl = New Polyline
                pGeoColl.AddGeometryCollection pSegColl
                Set pFeature.Shape = pGeoColl
                Debug.Print pSegColl.SegmentCount & " ## " & pFeature.OID
            End If
        End If
    Next pSegCounter
    pFCursor.UpdateFeature pFeature
    pFeature.Store


    pWorkSpaceEdit.StopEditOperation
    pWorkSpaceEdit.StopEditing True

    Set pFeature = pFCursor.NextFeature

   
Loop
txtStream.Close

End Sub
 
  Paritosh Gupta
Consultant- GIS Software
Mailto: paritosh.aps@gmail.com
Cell : +91 9810884817
 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: How to store updated feature? 
Author Tao Li 
Date Nov 05, 2009 
Message Great, thanks for the pointer
i used the idataset.workspace property to set workspace. and switched the update cursor creation inside edit session and it worked like a charm

I have one question thou, how come feature.store is used after featurecursor.update? 
 
Option Explicit

'MAKE SURE YOU HAVE EXCLUSIVE LOCK TO THE DATA YOU ARE CLEANING, OTHERWISE YOU GET DBASE LOCK ERROR
Public Sub EllipDetect()

Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pFLayer As IFeatureLayer
Dim pFClass As IFeatureClass
Dim pFCursor As IFeatureCursor
Dim pFeature As IFeature

Set pMxDoc = Application.Document
Set pMap = pMxDoc.FocusMap
Set pFLayer = pMap.Layer(0)
Set pFClass = pFLayer.FeatureClass


Dim logObject As Object
Set logObject = CreateObject("Scripting.FileSystemObject")
Dim txtStream As Object
Set txtStream = logObject.CreateTextFile("C:\Documents and Settings\TLI\Desktop\elliplog.txt")
'write gui for this part, use dlg
Dim txtString As String

Dim pGeom As IGeometry
Dim pSegColl As ISegmentCollection
Dim pSegCounter As Long
Dim pSegment As ISegment
Dim pToPoint As IPoint
Dim pFromPoint As IPoint
Dim pArcCenter As IPoint
Dim pISCCW As Boolean
Dim pEllipArc As IEllipticArc
Dim pCArc As ICircularArc
Dim SemiMajor As Double
Dim SemiMinor As Double
Dim MajMinRatio As Double
Dim pGeoColl As IGeometryCollection

' IMPORTANT, When updating a feature, you need to get ref to WorkSpace and Workspace edit below
' Otherwise you will get automation error, and start operation or you get edit oeration is required error
Dim pDataSet As IDataset
Set pDataSet = pFClass
Dim pWorkSpace As IWorkspace
Set pWorkSpace = pDataSet.Workspace
Dim pWorkSpaceEdit As IWorkspaceEdit
Set pWorkSpaceEdit = pWorkSpace
pWorkSpaceEdit.StartEditing True
pWorkSpaceEdit.StartEditOperation

Set pFCursor = pFClass.Update(Nothing, False)
Set pFeature = pFCursor.NextFeature
Do Until pFeature Is Nothing



    Set pSegColl = pFeature.ShapeCopy
    For pSegCounter = 0 To (pSegColl.SegmentCount - 1)
        Set pSegment = pSegColl.Segment(pSegCounter)
        If pSegment.GeometryType = esriGeometryEllipticArc Then
            Set pEllipArc = pSegment 'QI
            pEllipArc.GetAxes SemiMajor, SemiMinor, MajMinRatio
            If MajMinRatio < 0.9 Then 'This is tolerance
                txtString = pFeature.OID & " ## " & Str(pSegCounter) & "_Fix_by_Hand_"
                txtStream.WriteLine txtString
            Else
                Set pArcCenter = pEllipArc.CenterPoint
                Set pFromPoint = pEllipArc.FromPoint
                Set pToPoint = pEllipArc.ToPoint
                pISCCW = pEllipArc.IsCounterClockwise
                Set pCArc = New CircularArc
                pCArc.PutCoords pArcCenter, pFromPoint, pToPoint, pISCCW
                pSegColl.RemoveSegments pSegCounter, 1, False
                pSegColl.AddSegment pCArc
                pSegColl.SegmentsChanged
                Set pGeoColl = New Polyline
                pGeoColl.AddGeometryCollection pSegColl
                Set pFeature.Shape = pGeoColl
                Debug.Print pSegColl.SegmentCount & " ## " & pFeature.OID
            End If
        End If
    Next pSegCounter
    pFCursor.UpdateFeature pFeature
    pFeature.Store
    
    Set pFeature = pFCursor.NextFeature
   
Loop
txtStream.Close
pWorkSpaceEdit.StopEditOperation
pWorkSpaceEdit.StopEditing True
MsgBox "Operation Completed"
End Sub
 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: How to store updated feature? 
Author Paritosh Gupta 
Date Nov 05, 2009 
Message Hi Tao
I feel it should work even without pFeature.Store, as UpdateFeature method of IFeatureCursor is already updating the said feature. You can check by commenting this line. 
  Paritosh Gupta
Consultant- GIS Software
Mailto: paritosh.aps@gmail.com
Cell : +91 9810884817
 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: How to store updated feature? 
Author Hailiang Shen 
Date Nov 06, 2009 
Message 1 If you use pFeatureClass.search to get the cursor, you need to call pFeature.store,

2 If you use pFeatureClass.update to get the cursor, you need to call pFeature.UpdateFeature. 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: How to store updated feature? 
Author Tao Li 
Date Nov 09, 2009 
Message thanks for the pointers guys, it really helps for my understanding