Creating a list of features from a RowCursor

370
2
Jump to solution
12-13-2023 04:59 AM
EricPfirman
New Contributor III

I am using a RowCursor to build a List of Features. In the While loop, my debug statement returns OBJECTIDs 1 and 2, but in the For loop after the RowCursor, the OBJECTIDs are 2 and 2. Why?

 

 Dim mm as MapMember
 Dim pPointFeatures As List(Of Feature) = New List(Of Feature)
 Dim qf as ArcGIS.Core.Data.QueryFilter
 qf.WhereClause = "OBJECTID IN (1, 2)"
 Using c As RowCursor = CType(mm, BasicFeatureLayer).Search(qf)
	 While c.MoveNext
		 Debug.Print(CType(c.Current, Feature).Item("OBJECTID").ToString())
		 ' Prints 1 and 2
		 pPointFeatures.Add(CType(c.Current, Feature))
	 End While
 End Using
 For Each p In pPointFeatures
	 Debug.Print(p("OBJECTID").ToString())
	 ' Prints 2 and 2
 Next

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Your code is using a recycling cursor (the default method). You have set the useRecyclingCursor parameter to false when using the Search method.

Using c As RowCursor = CType(mm, BasicFeatureLayer).Search(qf, false)

 Read a little more about recycling cursors here

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

Your code is using a recycling cursor (the default method). You have set the useRecyclingCursor parameter to false when using the Search method.

Using c As RowCursor = CType(mm, BasicFeatureLayer).Search(qf, false)

 Read a little more about recycling cursors here

EricPfirman
New Contributor III

Wow! Thanks! I never knew. Small note, I had to add GetTable() so I could use the Table Search and then it worked.

Using c As RowCursor = CType(mm, BasicFeatureLayer).GetTable().Search(qf, False)

 

0 Kudos