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.

closed as off-topic by PolyGeo Nov 24 '18 at 22:46

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.


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]

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