Multipart To Singlepart (Data Management)


Creates a feature class containing singlepart features generated by separating multipart input features.


Multipart to Singlepart illustration



MultipartToSinglepart_management (in_features, out_feature_class)
ParameterExplanationData Type

The input features that can be any feature type.

Feature Layer

The output feature class containing features that vary with input feature type.

Feature Class

Code Sample

MultipartToSinglepart Example 1 (Python window)

The following Python window script demonstrates how to use the MultipartToSinglepart function in immediate mode.

import arcpy
from arcpy import env
env.workspace = "C:/data"
MultipartToSinglepart Example 2 (stand-alone script)

The following stand-alone script is a simple example of how to apply the MultipartToSinglepart function in a scripting environment.

# Name:
# Description: Break all multipart features into singlepart features,
#              and report which features were separated.
# Author: ESRI

# Import system modules
import arcpy
# Create variables for the input and output feature classes
inFeatureClass = "c:/data/gdb.gdb/vegetation"
outFeatureClass = "c:/data/gdb.gdb/vegetation_singlepart"

    # Create list of all fields in inFeatureClass
    fieldNameList = [ for field in arcpy.ListFields(inFeatureClass)]

    # Add a field to the input this will be used as a unique identifier
    arcpy.AddField_management(inFeatureClass, "tmpUID", "double")
    # Determine what the name of the Object ID is 
    OIDFieldName = arcpy.Describe(inFeatureClass).OIDFieldName
    # Calculate the tmpUID to the OID
    arcpy.CalculateField_management(inFeatureClass, "tmpUID",
                                    "[" + OIDFieldName + "]")
    # Run the tool to create a new fc with only singlepart features
    arcpy.MultipartToSinglepart_management(inFeatureClass, outFeatureClass)
    # Check if there is a different number of features in the output
    #   than there was in the input
    inCount = int(arcpy.GetCount_management(inFeatureClass).getOutput(0))
    outCount = int(arcpy.GetCount_management(outFeatureClass).getOutput(0))
    if inCount != outCount:
        # If there is a difference, print out the FID of the input 
        #   features which were multipart
                                 outFeatureClass + "_freq", "tmpUID")
        # Use a search cursor to go through the table, and print the tmpUID 
        print("Multipart features from {0}".format(inFeatureClass))
        for row in arcpy.da.SearchCursor(outFeatureClass + "_freq",
                                         ["tmpUID"], "FREQUENCY > 1"):
            print int(row[0])
        print("No multipart features were found")

except arcpy.ExecuteError:
    print arcpy.GetMessages()
except Exception as e:
    print e


Related Topics

Licensing Information

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes