多部件至单部件 (数据管理)

许可等级:BasicStandardAdvanced

摘要

创建包含通过分割多部件输入要素而生成的单部件要素的要素类。

插图

Multipart to Singlepart illustration

用法

语法

MultipartToSinglepart_management (in_features, out_feature_class)
参数说明数据类型
in_features

任意要素类型的输入要素。

Feature Layer
out_feature_class

所含要素视输入要素类型而定的输出要素类。

Feature Class

代码实例

MultipartToSinglepart 示例 1(Python 窗口)

以下 Python 窗口脚本演示了如何在即时模式下使用 MultipartToSinglepart 函数。

import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.MultipartToSinglepart_management("landuse.shp",
                                       "c:/output/output.gdb/landuse_singlepart")
MultipartToSinglepart 示例 2(独立脚本)

以下独立脚本是演示如何在脚本环境中应用 MultipartToSinglepart 函数的简单示例。

# Name: MultipartToSinglepart_Example2.py
# 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"

try:
    # Create list of all fields in inFeatureClass
    fieldNameList = [field.name 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
        arcpy.Frequency_analysis(outFeatureClass,
                                 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])
    else:
        print("No multipart features were found")

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

环境

相关主题

许可信息

ArcGIS for Desktop Basic:是
ArcGIS for Desktop Standard:是
ArcGIS for Desktop Advanced:是
9/15/2013