I have two shapefiles that I am a trying to compare to one another. The first set of points are various businesses. With assistance it was discovered that in order to get a subset category from that shapefile the following code should be used:

cat = 'ClothingStore'
arcypy.SelectLayerByAttribute_management("lyr","NEW_SELECTIION",'"category"='+"'%s'"% cat)

After I have isolated the subset category from the shapefile I want to compare that subset of points to another set of points that are all within a single shapefile called Churches.shp. I want to find all the ClothingStores points that are within a 500 radius of Church points.

How could this be done through ArcPy?

closed as off-topic by Dan C, aldo_tapia, whyzar, PolyGeo May 7 '18 at 20:12

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – Dan C, aldo_tapia, whyzar, PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Have you looked at select by location? I'd use the "within a distance" option. – smiller May 7 '18 at 14:49
  • Thanks. I see: SelectLayerByLocation_management (in_layer, {overlap_type}, {select_features}, {search_distance}, {selection_type}, {invert_spatial_relationship}). . . . . . . . . Would something like this work?: SelectLayerByLocation_management ('ClothingStore', 'WITHIN_A_DISTANCE', 'Churches.shp' , '500 Meters', '#', '#') – 2Ma_ May 7 '18 at 14:54
  • Not sure how I would specify the first in_layer as only those ClothingStore pts. – 2Ma_ May 7 '18 at 14:55
  • When you choose a layer that has already been subject to a select by attribute or select by location, by default it keeps your selection. What resources have you consulted for learning ArcGIS? There are some online courses including Lynda.com and other resources that might be helpful for getting familiar with the terminology and basic tools before you try to add in the arcpy component. – smiller May 7 '18 at 14:58
  • Thank you again. The original shp file said, DC_POI.shp, I suppose I could simple just put that as my in_layer, since it's already been established that it's only turning on ClothingStore pts. So then it would be this: SelectLayerByLocation_management ('DC_POI.shp', 'WITHIN_A_DISTANCE', 'Churches.shp' , '500 Meters', '#', '#') – 2Ma_ May 7 '18 at 15:00

In general, you can solve this using a combination of select by attributes and select by location. Select by attributes first on the overall points of interest file, and then select by location to find those selected POIs (clothing stores) within a distance of the churches layer. OR, select by location for all POIs within that distance, and subset that selection by attribute.

Check this answer for details on how to specify the distance units: How to specify units when using SelectLayerbyLocation_management WITHIN_A_DISTANCE?

Try to use the Python window within ArcGIS first as it can walk you through creating the script. Or create a model in Model Builder and then export the Python code.

  • Thank you. How does this look:. . . . arcpy.MakeFeatureLayer_management('DC_POI.shp','Clothing_lyr'). . . . .arcpy.MakeFeatureLayer_management('MetroStations.shp,'Stations_lyr'). . . . .arcpy.SelectLayerByAttribute_management ("Clothing_lyr", "NEW_SELECTION", "[NAME] = 'ClothingStore' ") . . . . . distance = 500. . . . .linearUnit = distance + " Meters" . . . . .arcpy.SelectLayerByLocation_management(targetLayer, "WITHIN_A_DISTANCE", inputLayer, linearUnit) – 2Ma_ May 7 '18 at 16:01
  • Also would you know what this means? • Use buffer analysis to buffer the metro stations by the user-specified radius and create a new shapefile. • Use Select Layer By Location analysis to select all POI that intersect your new buffered dataset. Remember that you have to make a feature layer before you do the selection. – 2Ma_ May 7 '18 at 16:16

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