Copiar Entidades de origen de trazado poligonal (ArcGIS 10.1 Network Analyst)

Nivel de licencia:BasicStandardAdvanced

Resumen

Crea dos clases de entidad y una tabla, que juntas contengan información sobre los bordes, cruces y giros que se trazan al resolver una capa de análisis de red.

Más información sobre la salida de la herramienta Copiar entidades de origen de trazado poligonal

Uso

Sintaxis

CopyTraversedSourceFeatures_na (input_network_analysis_layer, output_location, edge_feature_class_name, junction_feature_class_name, turn_table_name)
ParámetroExplicaciónTipo de datos
input_network_analysis_layer

La capa de análisis de red desde la que se copiarán las entidades de origen de traza poligonal. Si la capa de análisis de red no tiene un resultado válido, la capa se resolverá para producir una.

ArcGIS 10.1 Network Analyst Layer
output_location

El espacio de trabajo donde se guardarán la tabla de salida y las dos clases de entidad.

Workspace; Feature Dataset
edge_feature_class_name

El nombre de la clase de entidad que contendrá información sobre las entidades de origen de eje trazado. Si la capa de análisis de red resuelta no trace en forma poligonal cualquier entidad de eje, se crea una clase de entidad vacía.

String
junction_feature_class_name

El nombre de la clase de entidad que contendrá información sobre las entidades de fuente de unión de trazado poligonal, incluyendo los cruces del sistema y puntos relevantes de la capa de entrada de análisis de red. Si la capa de análisis de red resuelta no traza en forma poligonal cualquier cruce, se crea una clase de entidad vacía.

String
turn_table_name

El nombre de la tabla que contendrá información sobre los giros globales de trazado poligonal y entidades de giro que escalen el coste de los bordes subyacentes. Si la capa de análisis de red resuelta no traza en forma poligonal cualquier giro, se crea una tabla vacía. Puesto que los giros restringidos nunca se trazan, nunca se incluyen en la salida.

String

Ejemplo de código

CopyTraversedSourceFeatures ejemplo 1 (ventana de Python)

La siguiente secuencia de comandos de la ventana de Python muestra cómo utilizar la herramienta CopyTraversedSourceFeatures para escribir los ejes de trazado poligonal, cruces y giros desde una capa de análisis de red de Ruta a clases de entidad y tablas en un espacio de trabajo en memoria.

import arcpy
arcpy.na.CopyTraversedSourceFeatures("Route","in_memory",
                                     "TraversedEdges",
                                     "TraversedJunctions",
                                     "TraversedTurns")
CopyTraversedSourceFeatures ejemplo 2 (flujo de trabajo)

La siguiente secuencia de comandos de Python independiente muestra cómo se puede utilizar CopyTraversedSourceFeatures para buscar las calles que son comunes a las rutas de centroides de distrito censal de la estación de bomberos más cercana. Estos resultados ayudan a identificar qué calles son emergencias utilizadas más frecuentemente.

# Name: CopyTraversedSourceFeatures_ex02.py
# Description: The scenario shows how to find the streets that are common to the
#              routes between the closest fire station and the census tract
#              centroids. These streets can be used to identify critical points
#              in case of an emergency. 
# Requirements: Network Analyst Extension 

#Import system modules
import os
import arcpy
from arcpy import env

try:
    #Check out the Network Analyst extension license
    arcpy.CheckOutExtension("Network")

    #Set environment settings
    env.workspace = "C:/data/SanFrancisco.gdb"
    env.overwriteOutput = True
    
    #Set local variables
    inNetworkDataset = "Transportation/Streets_ND"
    outNALayerName = "EmergencyRoutes"
    impedanceAttribute = "TravelTime"
    inFacilities = "Analysis/FireStations"
    inIncidents = "Analysis/TractCentroids"
    edgeFrequency = "in_memory/EdgeFrequency"
    outLayerFile = "C:/data/output" + "/" + outNALayerName + ".lyr"
    outFeatures = "CriticalStreets"
    
    #Create a new closest facility analysis layer. For this scenario, the default 
    #value for all the remaining parameters statisfies the analysis requirements
    outNALayer = arcpy.na.MakeClosestFacilityLayer(inNetworkDataset, outNALayerName,
                                                   impedanceAttribute, "TRAVEL_FROM")
    
    #Get the layer object from the result object. The closest facility layer can 
    #now be referenced using the layer object.
    outNALayer = outNALayer.getOutput(0)
    
    #Get the names of all the sublayers within the closest facility layer.
    subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
    #Stores the layer names that we will use later
    facilitiesLayerName = subLayerNames["Facilities"]
    incidentsLayerName = subLayerNames["Incidents"]
    
    #Load fire station features as facilities and ensure that they are not
    #located on restricted portions of the network. Use default field mappings
    #and search tolerance
    arcpy.na.AddLocations(outNALayer,facilitiesLayerName,inFacilities,"", "",
                          exclude_restricted_elements = "EXCLUDE")
    
    #Load tract centroids as incidents and ensure that they are not located on
    #restricted portions of the network. Map the ID field from Tract Centroids
    #as the name for incidents using field mappings
    fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, incidentsLayerName)
    fieldMappings['Name'].mappedFieldName = "ID"
    arcpy.na.AddLocations(outNALayer,incidentsLayerName, inIncidents,
                          fieldMappings,"", exclude_restricted_elements = "EXCLUDE")
    
    #Solve the closest facility layer and copy the travered source features to a
    #temporary in-memory workspace. Use default names for the output feature
    #classes and table. Get only the first output which are the edges traversed.
    traversedEdges = arcpy.na.CopyTraversedSourceFeatures(outNALayer,
                                                          "in_memory").getOutput(0)
    
    #Calculate the frequency of SourceOID in the traversed edges
    arcpy.analysis.Frequency(traversedEdges, edgeFrequency,
                             ["SourceOID", "SourceName"])
    
    #Get the full path to the streets feature class by describing the network
    #dataset referenced by the network analysis layer. 
    network = arcpy.Describe(outNALayer.dataSource)
    edgeSources = network.edgeSources
    for es in edgeSources:
        if es.name.lower() == "streets":
            streetsSource = os.path.join(os.path.dirname(network.catalogPath),
                                         es.name)
            break
    else:
        raise Exception("Failed to detrmine the path for the streets feature class")
    
    #Join the frequency field to the streets feature class. In order to speed up
    #the join select the streets that share a line segment with traversed streets.
    streetsLayer = "StreetsLayer"
    arcpy.management.MakeFeatureLayer(streetsSource,streetsLayer)
    arcpy.management.SelectLayerByLocation(streetsLayer, "SHARE_A_LINE_SEGMENT_WITH",
                                           traversedEdges)
    arcpy.management.JoinField(streetsLayer, "ObjectID", edgeFrequency,
                               "SourceOID", "FREQUENCY")
    
    #Copy the streets that have a frequency value to a new feature class.
    arcpy.management.SelectLayerByAttribute(streetsLayer, "SUBSET_SELECTION",
                                            "FREQUENCY IS NOT NULL")
    arcpy.management.CopyFeatures(streetsLayer,outFeatures)
    
    #Delete the Frequency field from the streets feature class
    arcpy.management.DeleteField(streetsLayer, "FREQUENCY")

    #Save the solved na layer as a layer file on disk with relative paths
    arcpy.management.SaveToLayerFile(outNALayer,outLayerFile,"RELATIVE")
    
    print "Script completed successfully"
    
except Exception as e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "An error occured on line %i" % tb.tb_lineno
    print str(e)

Entornos

Temas relacionados

Información sobre licencias

ArcGIS for Desktop Basic: Requiere Network Analyst
ArcGIS for Desktop Standard: Requiere Network Analyst
ArcGIS for Desktop Advanced: Requiere Network Analyst
9/11/2013