Deleting output shapefiles which have no data/features using ArcPy?

المشرف العام

Administrator
طاقم الإدارة
Still working on cleaning this up but it runs fine. Below is the rough code for a tool that iterates through field rows and clips accordingly to that row's shape. Everything outputs nicely but there are some outputs that do not contain data. What can I add to have arcmap check for shapefiles containing no data and delete them?

Added an if statement to check for empty SHP's but not sure how to define where to have it check the output folder?

import arcpyfrom arcpy import envarcpy.env.workspace = r'path\folder'field = "PARISH"fc = arcpy.GetParameterAsText(0)Name = arcpy.GetParameterAsText(1)Path = arcpy.GetParameterAsText(2)rows = arcpy.SearchCursor(arcpy.env.workspace)for row in rows: feat = row.Shape outputName = Name.replace(" ", "_") outputField = row.getValue(field) outputFieldmod = outputField.replace(" ", "_") arcpy.Clip_analysis(fc, feat, str(Path) + r'/' + str(outputName) + "_" + str(outputFieldmod))for file in arcpy.ListFiles(): if arcpy.management.GetCount(file)[0] == "0": arcpy.management.Delete(file) arcpy.AddMessage('Deleted "{}" because it contains no features!'.format(file))

أكثر...
 
أعلى