I'm running a script to create a buffer and find features from another shapefile that fall completely within that buffer. The script seems to work fine, it finds all the correct features (I checked using intersect in Desktop ArcMap) but then creates an empty shapefile. The resulting shapefile has the right schema from the input shapefile but no features.
EDIT: Strangely it seems to work fine if I do it to a GDB instead of a shapefile.
# this program buffers a file and finds what features are inside that buffer # everything works except for writing to the new shapefile, and i can't figure out why # import all the goodies import ogr import gdalconst import sys import os import arcpy # set the workspace for arcpy arcpy.env.workspace = "c:/work/lab8" # set folders and files folder = 'C:\\work\\lab8\\' myFile = 'Parcels.shp' myFile2 = 'Powerline.shp' filename = folder + myFile # get all the attributes using describe and count the number of features desc = arcpy.Describe(myFile) cm = arcpy.GetCount_management(myFile) nFeatures =int(cm) print 'featureclass',myFile,'has',nFeatures,'features' print 'running tool' # make the new layers to select from arcpy.MakeFeatureLayer_management(myFile, "parcels_lyr") arcpy.MakeFeatureLayer_management(myFile2, "powerline_lyr") # set the buffer destination buffer_file = 'powerline_buffer.shp' buffer_output = folder+buffer_file # if the layer exists, delete it if arcpy.Exists(buffer_output): arcpy.Delete_management(buffer_output) #create the buffer bufferDist = 250 sideType = "FULL" endType = "ROUND" arcpy.Buffer_analysis("powerline_lyr", buffer_output, bufferDist, sideType, endType) # make the buffer result a layer arcpy.MakeFeatureLayer_management(buffer_output, "buffer_lyr") # run the intersect arcpy.SelectLayerByLocation_management('parcels_lyr', 'COMPLETELY_WITHIN', 'buffer_lyr', "", "NEW_SELECTION") # see how many features intersect. if 0, quit matchcount = int(arcpy.GetCount_management('parcels_lyr')) if matchcount == 0: print('no features intersect') sys.exit() else: print matchcount, 'intersected' # Set output file name out_name = "parcels_within.shp" out_location = folder+out_name print out_location # if the new featureclass exists, delete it # i took this out in case it was causing problems, but it doesn't seem to be the cause if arcpy.Exists(out_location): arcpy.Delete_management(out_location) print 'bye' # showing all the features that interserct, to make sure it works print '\nThese features of',myFile, 'intersect the buffer of',myFile2,': \n' cursor = arcpy.SearchCursor('parcels_lyr') for row in cursor: if row.getValue('SITUSADDR'): print row.getValue('SITUSADDR') # Write the selected features to a new featureclass # for some reason this creates an empty shapefile and I can't figure out why arcpy.CopyFeatures_management('parcels_lyr', out_location)