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 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
share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.