When using a cursor to loop through an attribute table, is it possible to iteratively select each row?

I want to clip a line to a polygon grid (see previous question); due to the size of the grid the split function fails. Hence I'm interested in selecting each polygon, and clipping the line to the selected cell by using the shapefile with only that cell selected.

I'm familiar with looping through the attribute table and performing calculations - but I don't know how to select a row.


Yes, use SelectLayerByAttribute_management() and select by FID.

| improve this answer | |
  • You got ahead of me! – Patrick Aug 17 '11 at 14:57
  • It would probably be faster to build a list of OIDs and do one Select by Attribute at the end rather than within the cursor. This won't work on Oracle if you have more than 1000 OIDs to select though (see this question). – blah238 Aug 17 '11 at 18:25
  • @blah238, the specific workflow that the OP is talking about involves selecting one OID at a time. Would this speed up that process? – Patrick Aug 17 '11 at 18:42
  • 1
    I see what you mean -- instead of selecting the feature and then calling clip, you could use the shape field (geometry object) of the current row as the clip features argument to the clip command. Might be a little faster. – blah238 Aug 17 '11 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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