Thursday 30 July 2015

arcpy - Getting list of selected features in ArcGIS for Desktop using Python code?


I have a question regarding selections in ArcGIS for Desktop. Assumed I have one layer in ArcMap and I have selected two of five features.


Is it possible to get a list of all selected features by using Python?


It would be fine if there is a way to get one special (or all) attribute(s) of the selected features stored in a list that can be written into a txt file.


Is it possible to do this in ArcGIS for Desktop?



Answer



Any time you have a selection on a layer a cursor object will only return the selected rows.


for row in arcpy.SearchCursor("name_of_layer_with_selection"):

print row.field1, row.field2

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...