Printing an add_to_selection features' message.

05-02-2020 04:11 PM
New Contributor II
‍‍‍‍‍‍‍‍‍‍‍‍‍#Creating features list for Buffer Analysis
fcList = ["schools.shp", "BroomeGroceryStores.shp"]

#Selecting schools that fall within 805 meters of a grocery store
buffList = []
for fc in fcList:
    buff = arcpy.Buffer_analysis("BroomeGroceryStoress.shp", "Results/BroomeGroceryStores_buffer.shp", "805 METERS")
print arcpy.GetMessages()
for buff in buffList:
    arcpy.SelectLayerByLocation_management("schools", "WITHIN", buff, 0, "ADD_TO_SELECTION")
print "Done"

Is there a way to print out how many features are selected under a buffer for analysis purposes using Python? I have the following script where I put an 805-meter buffer around grocery stores, and brought in a shapefile called schools and wanted to know how many schools fall within 805 meters (which is 0.5 miles) of a grocery store? When I run the script it shows me the selection of schools, but I was wondering if there was a way I can make the program print or create table full of values on how many features are selected under the buffering circle. Please let me know. Thank you!

0 Kudos
4 Replies
MVP Regular Contributor

You might get a better chance at a response if you post these types of questions to the Python‌ section of Geonet. Also, as Dan Patterson‌ mentioned in another post of yours, it's much easier to help and be able to reference line numbers if you use syntax highlighting and put your code in the actual post, rather than in an image attachment:




New Contributor II

Thanks, will keep this in mind for future reference. But also with the community thing, it didn't really let me put in GeoNet community as general, so I put in ArcGIS, because it had higher number of members. 

0 Kudos
MVP Regular Contributor

Also, maybe you could try using the GetCount method? It says in the documentation that "If the input is a layer or table view containing a selected set of records, only the selected records will be counted." So you could set the result of that method to a variable and then print that variable. 

Get Count—Help | ArcGIS for Desktop 

0 Kudos
MVP Esteemed Contributor