Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

This question already has an answer here:

I would like to split a single shapefile into multiple shapefiles by using unique values for one attribute/field to select features for each value out into a new feature class.

I found ET Geowizard to do this but it's not free.

In arcscripts.esri.com I found a tool named "SplitLayerByAttributes" but it does not work in ArcMap . (see comments below, this was an old version which has been updated. The new version can be found at resources.arcgis.com )

Do you know of any tools or solution to split by attribute in the way described above?

share|improve this question

marked as duplicate by PolyGeo 2 days ago

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
What do you mean when you say "Split by Attribute"? Do you want the attribute value used to select features out into a new feature class with all features sharing the same value? Or do you want the attribute value used to name the output feature class while it's geometry is used to clip? A diagram or link to a page would help make this clear so can you edit your Question, please? –  PolyGeo Mar 16 at 19:38
1  
The SplitLayerByAttributes tool was updated and can be found here resources.arcgis.com/gallery/file/geoprocessing/… –  Dan Patterson Mar 17 at 1:51
    
Has anyone used the model shown above? I am having an issue with it. I can see that it almost works, but it only saves the last feature that is selects when iterating. Thanks –  David Ainley Sep 18 at 17:33

7 Answers 7

up vote 3 down vote accepted

Here are some more free third-party tools that split by attribute:

share|improve this answer
    
+1 For recommending GME –  Aaron Jan 31 '13 at 16:38

I do not have access to ArcMap 10, only 9.3, but I expect that it won't be very different from this.

You can create a simple script in Python, that checks your attribute field for different values, and then, for each of them runs a SELECT operation to your original Shapefile.

If you are not familiar with python scripting, all you need to do is open you IDLE (the python GUI) create a new file, and copy the code below. After adapting the code for your my_shapefile, outputdir and my_attribute it should work.

# Script created to separate one shapefile in multiple ones by one specific
# attribute

# Example for a Inputfile called "my_shapefile" and a field called "my_attribute"
import arcgisscripting

# Starts Geoprocessing
gp = arcgisscripting.create(9.3)
gp.OverWriteOutput = 1

#Set Input Output variables
inputFile = u"C:\\GISTemp\\My_Shapefile.shp" #<-- CHANGE
outDir = u"C:\\GISTemp\\" #<-- CHANGE

# Reads My_shapefile for different values in the attribute
rows = gp.searchcursor(inputFile)
row = rows.next()
attribute_types = set([])

while row:
    attribute_types.add(row.my_attribute) #<-- CHANGE my_attribute to the name of your attribute
    row = rows.next()

# Output a Shapefile for each different attribute
for each_attribute in atribute_types:
    outSHP = outDir + each_attribute + u".shp"
    print outSHP
    gp.Select_analysis (inputFile, outSHP, "\"my_attribute\" = '" + each_attribute + "'") #<-- CHANGE my_attribute to the name of your attribute

del rows, row, attribute_types, gp

#END
share|improve this answer

Did you see Split Layer By Attributes tool updated for ArcMap 10 here? If it does not work you can use Split (Analysis) for your needs.

Splitting the Input Features creates a subset of multiple output feature classes. The Split Field's unique values form the names of the output feature classes. These are saved in the target workspace.

split

Example Code:

import arcpy
arcpy.env.workspace = "c:/data"
arcpy.Split_analysis("Habitat_Analysis.gdb/vegtype", "climate.shp", "Zone",
                     "C:/output/Output.gdb", "1 Meters")

I hope it helps you...

share|improve this answer
    
The built-in Split tool works great for your purposes if you create an extent rectangle the same size as your polygons you wish to split. –  ccn Jan 31 '13 at 16:25

You can achieve this with a very simple model if you have ArcGIS 10.0 or higher.

Create a model with Feature Iterator where the group by field is the attribute you wish to select by then send the output to the copy features tool using inline substitution to ensure a unique file name. The model is shown below:

Model for extracting by attribute

share|improve this answer

You can use a Search Cursor to loop through individual features in a feature class and write the geometries to unique feature classes. In this example, I use a feature class of the USA and export the states to new shapefiles:

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)
share|improve this answer

I know you can use an iterator in model builder, but if you prefer to use python here is something I came up with. Add the script to a toolbox with the parameters in order as Input shpfile, fields(multivalue,obtained from input), and workspace. This script will split the shapefile into multiple shapefiles based on the fields you select, and output them into a folder of your choice. Hope this helps. (This is the first time Ive posted a script. Please vote up if it helps you at all. Thanks a ton.)

import arcpy, re

arcpy.env.overwriteOutput = True

Input = arcpy.GetParameterAsText(0)  
Flds = "%s" % (arcpy.GetParameterAsText(1)) 
OutWorkspace = arcpy.GetParameterAsText(2) 


myre = re.compile(";")
FldsSplit = myre.split(Flds)

sort = "%s A" % (FldsSplit[0])
rows = arcpy.SearchCursor(Input, "", "", Flds, sort)

for row in rows:
    var = []
    for r in range(len(FldsSplit)):
        var.append(row.getValue(FldsSplit[r]))
    Query = ''
    Name = ''
    for x in range(len(var)):
        if x == 0:
            fildz = FldsSplit[x]
            Name = var[x] + "_"
            Query += (""" "%s" = '%s'""" % (fildz, var[x]))
        if x > 0:
            fildz = FldsSplit[x]
            Name += var[x] + "_"
            Query += (""" AND "%s" = '%s' """ % (fildz, var[x]))
    OutputShp = OutWorkspace + r"\%s.shp" % (Name)
    arcpy.Select_analysis(Input, OutputShp, Query)
share|improve this answer

This is an even easier way to do this... and it outputs into a GDB.

http://www.umesc.usgs.gov/management/dss/split_by_attribute_tool.html

download the tool from USGS, took me 3 minutes to do what i had been trying for 1 hour.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.