1

I have a shapefile of a US. I need to make an individual shapefile for all the states in the US using a python in ArcGIS. How can I do it?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
user28725
  • 11
  • 2

2 Answers2

1

If you have a list of the states you can do something similar to the following:

import arcpy

statelist = [row.getValue('STATE_NAME') for row in arcpy.SearchCursor("INPUT DATASET")]

for state in statelist:
    arcpy.Select_analysis("INPUT DATASET", str(state), '[STATE_NAME] = "' + str(state) + '"')
dklassen
  • 2,920
  • 15
  • 25
  • Do i have to write the name of all the 52 states in the statelist ? – user28725 Apr 01 '14 at 18:53
  • You can use this: statelist = [row[0] for row in arcpy.da.SearchCursor(fc, ("NAME))] – ianbroad Apr 01 '14 at 19:01
  • For 10.0 you cannot use the 'da' option on the search cursor - so this will work: statelist = [row.getValue('STATE_NAME') for row in arcpy.SearchCursor("INPUT DATASET")] – dklassen Apr 01 '14 at 20:03
1

I would loop through each feature in the FC and write the geometry to a new FC.

import arcpy

# This is a path to an ESRI FC of the USA
states = r'C:\Program Files (x86)\ArcGIS\Desktop10.2\TemplateData\TemplateData.gdb\USA\states'
out_path = r'C:\temp'

with arcpy.da.SearchCursor(states, ["STATE_NAME", "SHAPE@"]) as cursor:
    for row in cursor:
        out_name = str(row[0]) # Define the output shapefile name (e.g. "Hawaii")
        arcpy.FeatureClassToFeatureClass_conversion(row[1], out_path, out_name)
Aaron
  • 51,658
  • 28
  • 154
  • 317