I have found a few different files containing the entire United States, with attributes including states. Is there a way to separate the states out into their own files (perhaps in one file geodatabase)? I later would like to use "Selection-> Select by State." While I can select each state individually and save them in one file geodatabase, I am wondering if there is a more efficient and quick way to do this. Also, any options I have found will not include both North Carolina and North Dakota, etc., because the state name is two words long. Instead I get one 'North.' I do not yet know Python.
3 Answers
Split Layers by Attributes check out this python toolbox. Split Layer by Attributes, State Name, being the attribute you want.
- 6,916
- 2
- 24
- 42
-
Please note the link in this answer goes to the 9.2 or higher but still 9.x version of the tool. The 10.x version of this particular script is currently not available (see comments on the accepted answer at the one this is marked duplicate of). There are also other alternatives out there that are for 10.x (some of which are also mentioned in other answers at that question). – Chris W Mar 26 '15 at 05:37
I suggest a model-builder based solution.
You can create a simple work flow that look as follow:
- Iterate by row selection
- extract the Name of each country using Get Field Value (model tools)
- Save Selected with Country name using the copy features tool; using
%I_NAME%to mark feature name with the selected country name, where I_NAME is the variable name of the Get Field Value Tool.

- 3,146
- 20
- 32
OK, here is the script I wrote a while back, and I just adjusted it for US States, but it will work for any kind of data, as long as it contains a column with unique values.
import arcpy
print 'imports over'
arcpy.env.overwriteOutput = True
# load dataset
states = r"F:\Data\States\States_2010.shp"
# create feature layer
arcpy.MakeFeatureLayer_management(states,'states_temp')
print 'Number of States: ' + str(arcpy.GetCount_management('states_temp'))
for row in arcpy.SearchCursor('states_temp'):
name = str(row.name10)
query = '"name10" = \'' + name + '\''
arcpy.SelectLayerByAttribute_management('states_temp',"NEW_SELECTION",query)
if " " in name:
name = name.replace(" ", "")
arcpy.CopyFeatures_management('states_temp',r"F:\randomGISstuff\states\exports\\" + name + ".shp")
print 'done'
How this works (simplified explanation; just the basic steps, not line by line):
- loop through the file, and for each feature get its name
- use that name to then select the row, and export just that row (i.e. that feature)
- when exporting use the name as the new file's name
This works well and fast. It also takes care of names that would have spaces in them. For example, North Carolina would be exported to NorthCarolina.shp instead of North Carolina.shp.
To illustrate this (and I apologize, these screenshots will be coming from QGIS... ArcGIS license has expired at home):
I have a shapefile of the USA:

Now, I would like to use the column NAME10 to use as the names for my exported files:

After running the script I will be left with this, all of them separate datasets:

Now, specifically to get it to work with your data, as you have not done any coding before, there are some parts you need to adjust.
I would recommend copy/pasting this code to a text editor or an IDE, such as Notepad++ or PyScripter, respectively. Save it as a file with a py extension, such as featuresToShp.py.
Then you need to edit the following lines:
7: insert the path to your dataset
15 and 16: change NAME10 to the field in your dataset that contains the state names
23: insert the path where you want to save your new files (the path/folder needs to exist before running the script!)
Then save, double click your .py file, and see the files magically appear in your specified folder :-)
- 6,637
- 4
- 38
- 64
Failed to execute (SplitLayerByAttributes).
– WolverineTime Mar 25 '15 at 13:53