I have a feature class containing 380 polygons representing sedimentary basins and another polygon feature class representing oil discoveries within said basins. My plan is to:

  • Iterate through all basins and select all fields that fall within them.
  • Reverse sort by a oil recoverable volume attribute (largest to smallest).
  • Sub-select the first 5 rows of the selection and export this to a feature class (other rows will be appended).

The first two steps I think I am ok with however, I'm stuck on how I would go about creating the sub-set where the first 5 rows are selected and then exported. If there are <5 rows, all will be selected, if there are 0 rows they will be ignored.

How, using ArcGIS Desktop 10.2, can I achieve the goal of selecting the first 5 rows of a selection?

The da.SearchCursor can be used to sort but not sure after that.


Not seeing your code, this may not work for you, but you can try to use the Python list selector:

for row in sorted(arcpy.da.SearchCursor(fc, [f1, f2]))[:5]
| improve this answer | |

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