Multi-parties vers une partie (Gestion des données)

Niveau de licence :BasicStandardAdvanced

Récapitulatif

Crée une classe d'entités qui contient des entités en une partie générée en séparant des entités multi-parties en entrée.

Illustration

Illustration de l'outil Multi-parties vers une partie

Utilisation

Syntaxe

MultipartToSinglepart_management (in_features, out_feature_class)
ParamètreExplicationType de données
in_features

Entités en entrée qui peuvent être de tout type.

Feature Layer
out_feature_class

Classe d'entités en sortie contenant des entités qui varient avec le type d'entité en entrée.

Feature Class

Exemple de code

Exemple 1 d'utilisation de l'outil MultipartToSinglepart (fenêtre Python)

Le script de fenêtre Python suivant montre comment utiliser la fonction MultipartToSinglepart en mode immédiat.

import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.MultipartToSinglepart_management("landuse.shp",
                                       "c:/output/output.gdb/landuse_singlepart")
Exemple 2 d'utilisation de l'outil MultipartToSinglepart (script autonome)

Le script autonome suivant dessous est un exemple d'application simple de la fonction MultipartToSinglepart dans un environnement de scripts.

# 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

Environnements

Thèmes connexes

Informations de licence

ArcGIS for Desktop Basic: Oui
ArcGIS for Desktop Standard: Oui
ArcGIS for Desktop Advanced: Oui
6/5/2014