2

I use the following nested loops to read the first point feature of a dataset and the rest points in that dataset. Then read the second point feature of a dataset and the rest points in that dataset and so on. The problem with these nested loops is that it reads the first point and the rest points only once. Why this happens?

Dim pFCursor As IFeatureCursor
Set pFCursor = pFeatureClass.Search(Nothing, True)
Dim pFCursor2 As IFeatureCursor
Set pFCursor2 = pFeatureClass.Search(Nothing, True)
Dim pFeature As IFeature
Dim pFeature2 As IFeature
Dim pPointA As IPoint
Dim pPointB As IPoint
Set pFeature = pFCursor.NextFeature
Do Until pFeature Is Nothing
Set pPointA = pFeature.Shape
MsgBox pFeature.Value(intPosFID) & "F1"
 Set pFeature2 = pFCursor2.NextFeature
 Do Until pFeature2 Is Nothing
 Set pPointB = pFeature2.Shape
 MsgBox pFeature2.Value(intPosFID) & "F2"
 Set pFeature2 = pFCursor2.NextFeature
 Loop
 Set pFeature = pFCursor.NextFeature
 Loop
whuber
70.4k16 gold badges189 silver badges285 bronze badges
asked Oct 18, 2011 at 6:40

1 Answer 1

3

The explanation is over on the ICursor interface (which FeatureCursor implements). You need to move Set pFCursor2 = pFeatureClass.Search(Nothing, True) into your first loop. Or set your recycling cursor to false, make one pass over your pFCursor2 cursor to create a collection of IFeature (List, Dictionary, etc) and then iterate over the collection.

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/ICursor_Interface/00250000011s000000/

Cursors are forward only; they do not support backing up and retrieving rows that have already been retrieved or making multiple passes over data. If an application needs to make multiple passes over the data, the application needs to reexecute the query that returned the cursor.

answered Oct 18, 2011 at 11:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.