5

First to describe my problem as I see it. I've been asked to design a tool that will take a selected features attributes and copy it out to an output table, with each successive selection and processing of the tool adding a new row to the formerly mentioned output table. I'm trying to work exclusively in Python since my VB knowledge is None (or perhaps Null?).
My current method has been to make a Layer View consisting only of the feature that the user has selected and then use a search cursor to snatch the data and populate the other table with use of an insert cursor. This seems clearly inefficient to me, but more appropriate methods have not made themselves clear to me. However, to make matters worse, it would seem that my Layer View is simply creating a copy of the original table because I don't have a method for singling out a unique identifying attribute to create a Layer View with 1 feature.

A couple of questions, then.

1) Is it possible through python/arcpy to access the attributes of a currently selected feature?
2) If this is not possible, what are other methods that come to mind for performing the task of extracting data from one feature class and using it to populate fields in a separate table?

1
  • This highlights the paucity of record-level data access tools provided with arcpy, in contrast, for example, the ease with which you can navigate through data tables with VB / MS Access. In engineering-related GIS work, it is often necessary to access and modify data at the individual row level, as is commonly done in non-spatial databases. Feature layers and the insert, search and update cursors comprise a basic and clunky toolset to do this.
    – user13366
    Commented Dec 6, 2012 at 5:29

1 Answer 1

10

All tools and methods in Python use the selected set if there is one or if there is no selection it uses the whole feature class.

You must be making sure that your input to the script is of Feature Layer type when setting the script up in the toolbox not Feature Class. Then for the input of cursors and tools you input the parameter Feature Layer from which the user has selected in the drop down.

More information on cursors can be found here:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001q000000.htm

1
  • 1
    You got it. Turns out I was somehow messing up the view creation in my call to the tool. The cursors are working as intended. Thanks.
    – Nathanus
    Commented Mar 16, 2011 at 16:25

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