Deleting selected features with ArcPy?

المشرف العام

Administrator
طاقم الإدارة
I am having trouble deleting the features I have selected using 'arcpy.SelectLayerByLocation_management' tool. To use the select layer by location tool, you much pass in a .lyr file. My script SHOULD create a .lyr file of the input data, select by location on the .lyr file, make a copy of the selected features and save to a .shp file, and then delete the selected features in my input data. Instead, it creates a .lyr file, selects features in the layer file and makes a copy of the layer file (correct up until this point). Then it deletes the .lyr file and im stuck at with an unchanged input data set. Should i make a copy of the .lyr file after i have used the arcpy.DeleteFeatures_management tool?

I guess the question in fewer words is:

When i call the arcpy.DeleteFeatures_management tool on a .lyr file that has selected features, does it delete the entire .lyr file or just the selected features?

Here is my code:

def dBaseComparison(self): '''This function compairs the input data to the database and selects the features that already exist''' try: # Create a feature layer to select the points that already exist in the database. arcpy.MakeFeatureLayer_management(self.MakeXYeventLayer(), 'PointInFile.lyr') arcpy.SelectLayerByLocation_management('PointInFile.lyr', "ARE_IDENTICAL_TO", self.dBase) # Make a copy of the existing features and delete them from the new file. arcpy.CopyFeatures_management('PointInFile.lyr', self.MakeXYeventLayer()[:-4] + "_selected.shp") arcpy.DeleteFeatures_management('PointInFile.lyr') return self.MakeXYeventLayer() except arcpy.ExecuteError: return arcpy.GetMessages( )

أكثر...
 
أعلى