#### Exports all polygons in FC into individual FCs in different location import arcpy, os, sys, traceback arcpy.env.workspace = 'G:\\PROJECTS\\Cedar\\Environmental\\FEMA\\Results\\lidar.gdb' arcpy.env.overwriteOutput = True outpath = 'G:\\PROJECTS\\Cedar\\Environmental\\FEMA\\Results\\Processing.gdb' floodbuff = '\\FloodplainAE_1000ft' flyr = 'Stream_Reach' try: arcpy.MakeFeatureLayer_management(floodbuff, flyr) result = arcpy.GetCount_management(flyr) print result print 'Exporting polygon features into their own fc' fid = 1 while fid <= result: query = '"ID" = ' + str(fid) arcpy.SelectLayerByAttribute_management(flyr, 'NEW_SELECTION', query) # Copy selected polygon into its own FC arcpy.CopyFeatures_management(flyr, outpath + os.sep + flyr + str(fid)) fid += 1 print 'All polygons exported successfully' except: arcpy.AddError(arcpy.GetMessages(2))
Solved! Go to Solution.
import arcpy import os # Phase I: Select and export individual polygons from the Polygon input file count = 0 copyRow = "" rowSearch = arcpy.SearchCursor( <<POLYGON FILE HERE>> ) for row in rowSearch: if copyRow != row.FID: copyRow = row.FID # Polygon output variable after Select tool has run pathPoly = <<WORKSPACE>> + '\ <<POLYGON NAME>>' + str(count)+ ".shp" # FID for Select tool FID = "\"FID\" = " + str(count) << GIVE UNIQUE IDENTIFIER HERE >> # Select tool to export individual polygons by row from the input variable arcpy.Select_analysis(Polygons, pathPoly, FID)
if copyRow != row.FID: copyRow = row.FID
if copyRow != row.FID: count = row.getValue("FID") copyRow = row.FID