Select to view content in your preferred language

Export Selected Features from Multiple Layers to Report, Excel, or Text Field

4635
3
06-02-2011 02:34 PM
KarlZimmer
Deactivated User
Hello,

I have a map document with numerous layers. I am looking for a tool or script (preferablly python or potentially VBA) that allows me to select certain features in a polygon layer and then uses this layer to select all features from the other layers in the TOC that intersect this polygon layer. Once features are selected I would like to export the attibute information selected from each layer in the TOC to a report, excel workbook, or txt file. So basically I'm looking to create an summary of all selected features that exist in a certain location as defined by the spatial extent of the polygon layer.

Ideally it would be a report that would show the layer name followed by the attribute information of the selected features; although a excel sheet or text file would suffice.

An example report for layers titled county, vegetation community, watershed, and wildlife management area and their  respective selections within each may look something like this:

County:
County of Highlands

Vegetation Community:
Deciduos Forest
Conifer Forest
Grassland

Watershed:
Bow River

Wildlife Mangement Area:
306
308

Thank in advance.
0 Kudos
3 Replies
JonOrsak
New Contributor
I'm looking for the same functionality.  Has anyone answered this question?
0 Kudos
KarlZimmer
Deactivated User
Hello,

I never recieved any responses, but found away to export to a text file within ArcGIS 10 using Python and ArcPy. Follow instructions here as a start: http://www.esri.com/news/arcuser/0111/charmsnake.html

I then modified the script so I could select by attribute and location and then using the following code I am able to loop through the rows in the attribute table and get the values for each of the fields (excluding objectid,shape_length and shape_area fields) and export them to the text file.

[HTML]                featcur = arcpy.SearchCursor(lyr)

                for f_row in featcur:             
                    fieldList = arcpy.ListFields(lyr)                                  
                    reportText += '\t\t\t__________________________________________' + '\n'
                    for field in fieldList:
                        fieldname = field.name
                        if fieldname == "OBJECTID" or fieldname == "SHAPE" or fieldname == "Shape" or fieldname == "Shape_Area" or fieldname == "Shape_Length" or fieldname == "SHAPE_Length" or fieldname == "SHAPE_Area":
                            arcpy.AddMessage("Skipped " + fieldname)                   
                        else:
                            featvalue = f_row.getValue(fieldname)
                            arcpy.AddMessage(field.name + " = " + str(featvalue))
                            reportText += '\t\t\t ' + str(fieldname) + ': ' + str(featvalue) + '\n'
                    ##reportText += '\t\t ___________________________________________________________' + '\n'

[/HTML]


Hope this helps.
0 Kudos
AdrianMarsden
Honored Contributor
Karl

I came here with the same query and am just looking at the original page you linked to.  I've then quickly looked at you code - is it complete?  It seems to be missing some -- there seem to be several FOR loops started but not finished - or am I missing something?

Cheers

ACM
0 Kudos