Dolichonyx

Unable to access selection from SelectLayerByLocation_management

Discussion created by Dolichonyx on Mar 14, 2012
Latest reply on Mar 14, 2012 by mzcoyle
I am having difficulty accessing the results from a select by location.  When I use CopyFeatures to copy my final file, I get a copy of the original file without the selection instead of just the selected features.  I had the same problem with ModelBuilder (but there I could at least see that it was selecting the features).

Is there a simple way to get this to work?  The code is below.


import arcpy

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

#Turn Overwrite on - keep from getting 1,000,000 files!
arcpy.env.overwriteOutput = True

for counter in range(0,1): #Text after this is indented, not sure why it is not showing up indented in the post.
      arcpy.MakeFeatureLayer_management("Z:\\Code\\Block%i.shp" % counter, 'routes%i_lyr' % counter)
      in_layer = 'routes%i_lyr' % counter
      select_features = "Z:\\Code\\Route_starts2.shp"
      arcpy.SelectLayerByLocation_management (in_layer, "WITHIN_A_DISTANCE", select_features, 3500, "NEW_SELECTION")
      arcpy.CopyFeatures_management(in_layer, "Z:\\Code\\Block%iMod.shp" % counter)

Outcomes