Select to view content in your preferred language

Swapping results of a query

834
1
11-29-2010 12:22 PM
ChristopherJursa
Emerging Contributor
Hello,

I am attempting to iterate through the results of a query and save the previous result to use in an operation with the next result.

I am saving the feature returned from the current cursor in a (previous feature) variable for the next iteration.  I am trying to make a series of lines from a shapefile of points.

My code is below.  Note in the while loop, the swap, which does not appear to work.

Any suggestions would be appreciated.  Thanks in advance!


# get an original selection
gp.MakeFeatureLayer_management(shpPath, 'myQuery')
gp.SelectLayerByAttribute('myQuery', 'NEW_SELECTION', '', '', '', 'pointID A')
myCursor = gp.SearchCursor('myQuery')
curFeature= vertexCursor.Next()

while (curVertexFeature):

     prevFeature = curFeature
     curFeature = myCursor .Next()
 
     print str(prevFeature.getValue('pointID')) + ',' + str(curFeature.getValue('pointID'))

0 Kudos
1 Reply
ChrisSnyder
Honored Contributor
Not sure if it would help in this case, but the .fidset property of a featurelayer that contains selections is a pretty usefull thing. Basically it just returns a delimited string of all the OBJECTIDs that you have selected. Perhaps in the cursor then, you could cross refernce the cursor with the OBJECTIDs in fidSetList. For example:

fidSetList = gp.describe(featureLayer).fidset.split(",") #Note: the feature layer has to have a selected set
0 Kudos