0

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.

WolverineTime
  • 359
  • 1
  • 10
  • 19
  • Can you post a screenshot of your attribute table, or let me know what the column is called that holds the State names? I wrote a script that does this, as a proof of concept. I would be glad to share it with you, but I would have to make some adjustments. – BritishSteel Mar 18 '15 at 15:56
  • Ah, the column that has the state names is called Name. Thank you – WolverineTime Mar 20 '15 at 21:36
  • You've edited to include a statement that 'options you have found' aren't working for cases where there is a space in the name. The tools I've worked with of this nature shouldn't be affected by this, as it looks at the entire attribute. Can you specifically indicate which you've tried? Also, if it's just states in the file you don't need to use the name field, as the OID should also be unique to each record and you can split on that. – Chris W Mar 20 '15 at 22:07
  • Hi, I went to Toolbox -> analysis tools -> extract -> split by name -> save into geodatabase. If I don't split by 'name', though, each feature class (state) will not be titled with that state's name. – WolverineTime Mar 23 '15 at 14:41
  • That's not the correct tool to use. That Split is used to cut up one set of data by using another set of polygons (see graphic example at link). The split by attributes tools mentioned below and at the duplicate question must be downloaded separately - there's no equivalent/default tool included in Arc that can perform the task. – Chris W Mar 23 '15 at 23:57
  • Chris, thank you for the clarification. I should not have used 'split.' I just attempted to use 'split layers by attributes' (the python toolbox mentioned below). But I received the following error: KeyError: 'ARCGISHOME'

    Failed to execute (SplitLayerByAttributes).

    – WolverineTime Mar 25 '15 at 13:53
  • The version linked to below is for 9.x. There is a version for 10.x, but due to Esri shuffling around their site it isn't linked anywhere right now (see the comments on the accepted answer at the duplicate question - the actual script author is participating there). Down near the bottom of the answers is one by David Ainley which links to a different tool that does the same thing produced by the USGS, and it has versions for 10.1 and 10.2. I would suggest trying one of those or contacting Dan for the 10.x version of his script. – Chris W Mar 26 '15 at 05:35

3 Answers3

5

Split Layers by Attributes check out this python toolbox. Split Layer by Attributes, State Name, being the attribute you want.

Maksim
  • 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
1

I suggest a model-builder based solution.

You can create a simple work flow that look as follow:

  1. Iterate by row selection
  2. extract the Name of each country using Get Field Value (model tools)
  3. 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.

WorkFlow

dof1985
  • 3,146
  • 20
  • 32
1

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: enter image description here

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

enter image description here

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

enter image description here




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 :-)

BritishSteel
  • 6,637
  • 4
  • 38
  • 64