CopyFeatures not recognizing selected features in arcPy script

238
3
Jump to solution
11-30-2021 01:03 PM
PhilCrossley1
New Contributor III

Hi. Have appreciated past help.

I'm trying to incorporate an attribute query into an arcpy script, and then work with the results of that query in a subsequent for: loop.

The script snippet below successfully creates the Indiana folder and GDB, and selects the Indiana counties, and creates a new INcounties feature class, as intended, BUT the new feature class includes ALL the US counties, not just the selected IN counties.

would appreciate any suggestions!

arcpy.CreateFolder_management(r"E:\advAppScripting\testing\tornhazard", "Indiana")
arcpy.CreateFileGDB_management(r"E:\advAppScripting\testing\tornhazard\Indiana", "IN_data")
arcpy.SelectLayerByAttribute_management("counties.dbf", "NEW_SELECTION",
""""STATE_NAME" = 'Indiana'""")
arcpy.CopyFeatures_management(r"E:\advAppScripting\testing\tornhazard\counties_layer",
r"E:\advAppScripting\testing\tornhazard\Indiana\IN_data.gdb\INcounties")

 

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

Select Layer By Attribute (Data Management)—ArcGIS Pro | Documentation

you may need to make a layer or table view first since it is apparently just copying counties_layer over without any selection

arcpy.management.SelectLayerByAttribute(in_layer_or_view, {selection_type}, {where_clause}, {invert_where_clause})

  


... sort of retired...

View solution in original post

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

Select Layer By Attribute (Data Management)—ArcGIS Pro | Documentation

you may need to make a layer or table view first since it is apparently just copying counties_layer over without any selection

arcpy.management.SelectLayerByAttribute(in_layer_or_view, {selection_type}, {where_clause}, {invert_where_clause})

  


... sort of retired...
0 Kudos
PhilCrossley1
New Contributor III

had been trying to find a way to add a tool parameter, or a step in btw. the selection and the copy Features, but you're right (as I've come to expect!):  when I run MakeFeatureLayer first, to create a counties_lyr, then run the query and the copyFeatures (set to export the (selected features in the) counties _lyr), it works exactly as intended...I don't think the Pro help files makes the need to follow this order of operations clear at all!  I sure appreciate the quick, and helpful, help!

0 Kudos
DanPatterson
MVP Esteemed Contributor

No problem Phil.  I have a preference to use the Python tab out of the Dialog Python under Parameters... there is often more information there and the parameter specification tends to be clearer (to me at least)


... sort of retired...
0 Kudos