1

I wanted to know if I am on the right track here with what I am trying to do. I have two shapefiles, the first contains point data for all the businesses in DC and the other contains point data all the Metro stations in DC. What I am trying to accomplish is to find all the businesses that are within a 500 Meter radius of a metro station, then find all coffee shops that are within a 500 meter radius of a metro station.

Here is what I have so far:

import arcpy    
arcpy.env.workspace = 'C:/Users/new/Desktop/'   
arcpy.MakeFeatureLayer('DC_POI.shp','DCPts')
arcpy.MakeFeatureLayer('DC_MetroStations.shp','StationPts')   
arcpy.Buffer_analysis('StationPts','MyShapefile.shp','500 Meters','#','#','#','#','#') 
arcpy.SelectLayerByLocation_management('DCPts','intersect','StationPts')
arcpy.SelectByAttribute_management('DCPts','SUBSET_SELECTION',"category='CoffeeShop'")  
counter = arcpy.GetCount_management('DCPTs')
print(counter)

when it prints counter, it is 0. I want to after every selection analysis to count the number of POI that are still selected in the layer.

I know I should use buffer analysis to buffer the metro stations by the that radius and create a new shapefile. So I think that was accomplished. And then use Select Layer By Location analysis that way I select all POI that intersect the new buffered dataset.

  • 1
    Why are you asking if it will work? What happens when you try to run it? – Jon May 7 '18 at 20:36
  • @Jon I don't know if it logically makes sense. I ran the program and it created the MyShapefile.shp on my desktop but when I went to open it nothing appears on Arcmap. Also nothing prints for the print(counter) – Htom May 7 '18 at 20:39
  • 1
    That is vital information to include in your question if you wish to get a useful answer! (I don't use Arc or arcpy, so I won't be much help). – Jon May 7 '18 at 20:40
  • @Jon I updated. Also when it prints it comes up 0 – Htom May 7 '18 at 20:41
  • 1
    Update your question with changes you've made to the code, as well as the new outputs you're getting... – Jon May 7 '18 at 21:01
2

Edit your code in that way: (Brief description is in the code)

import arcpy

arcpy.env.workspace = 'C:/Users/new/Desktop/'    
arcpy.MakeFeatureLayer('DC_POI.shp','DCPts')    
arcpy.MakeFeatureLayer('DC_MetroStations.shp','StationPts')

# Create buffers   
arcpy.Buffer_analysis('StationPts','MyShapefile.shp','500 Meters')

# Load buffer to memory
arcpy.MakeFeatureLayer('MyShapefile.shp','Buffer')

# Select points which intersects with buffers
# You must select points in buffer 
arcpy.SelectLayerByLocation_management('DCPts', 'INTERSECT', 'Buffer')

counter1 = arcpy.GetCount_management('DCPTs')
print("Businesses within 500m radius of a metro station: " + str(counter1) )

# Select coffee shops from just selected points
arcpy.SelectByAttribute_management('DCPts', 
                                   'SUBSET_SELECTION',
                                   "category='CoffeeShop'")

counter2 = arcpy.GetCount_management('DCPTs')    
print("CoffeeShops within 500m radius of a metro station: " + str(counter2) )
  • By passing a search distance to SelectLayerByLocation, you can bypass the buffering. SelectLayerByLocation_management('DCPts', 'INTERSECT', 'StationPts', '500 METERS') – Tom May 16 '18 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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