GetNAClassNames

Resumen

Returns a dictionary of network analysis class names from the network analysis layer specified as argument. The dictionary keys are the network analysis class names, and the values are the layer names that reference the network analysis classes from the network analysis layer. The layer names are used as input in some geoprocessing tools such as Add Locations and Add Field To Analysis Layer.

Debate

A network analysis layer is made up of one or more network analysis classes. Each network analysis class is a feature layer or a table view that references a feature class or a table. This function returns a mapping between those feature class or table names and their corresponding feature layer or table view names. The layer names are not constants, as they can be edited by an end user or can be localized by a foreign language version of ArcGIS. This function helps to write portable script code that runs across different ArcGIS language versions. The dictionary keys always remain constant and can be used to obtain the variable layer name for a given network analysis class.

Network analysis classes have various characteristics depending on the network analysis layer. Some of the classes are used to store inputs that are used during analysis, while some are used to store the outputs obtained from solving the analysis layer. The classes can also have location fields or location ranges if they act as network locations and have different shape types such as points, lines, or polygons or no shapes (in other words, tables). The naclass_edit_type, nalocation_type, and shape_type arguments can be used to further filter the list of network analysis classes. For example, the Sub Layer parameter in the Add Locations tool lists only those network analysis classes that support input edit mode, so such a list can be obtained by using INPUT as the value for the naclass_edit_type argument.

Sintaxis

GetNAClassNames (network_analyst_layer, {naclass_edit_type}, {nalocation_type}, {shape_type})
ParámetroExplicaciónTipo de datos
network_analyst_layer

A variable that references a Layer object obtained from a network analysis layer. It can be derived from existing layers in a map document or by specifying the catalog path to the network analysis layer file as an argument to the Layer class. The isNetworkAnalystLayer property on the Layer object can be used to identify whether a given Layer object is a network analysis layer.

Layer
naclass_edit_type

A string that specifies which network analysis classes are included in the output dictionary based on their edit mode in the network analysis layer. The argument value can be one of the following string keywords:

  • ANYInclude all the classes from the network analysis layer. This is the default value.
  • INPUTInclude only those classes that support an input mode in the network analysis layer. This option will also include classes that support both input and output modes.
  • OUTPUTInclude only those classes that support an output mode in the network analysis layer. This option will also include classes that support both input and output modes.

(El valor predeterminado es ANY)

String
nalocation_type

A string that specifies which network analysis classes are included in the output dictionary based on their support for location fields. The argument value can be one of the following string keywords:

  • ANYInclude the classes from the network analysis layer irrespective of whether they do or do not support location fields. This is the default value.
  • LOCATIONInclude only those classes from the network analysis layer that support location fields or location ranges.
  • NOT_LOCATIONInclude only those classes from the network analysis layer that do not support location fields or location ranges.

(El valor predeterminado es ANY)

String
shape_type

A string that specifies which network analysis classes are included in the output dictionary based on their shape type. The argument value can be one of the following string keywords:

  • ANYInclude all shape type classes from the network analysis layer. This is the default value.
  • POINTInclude only point classes from the network analysis layer.
  • LINEInclude only line classes from the network analysis layer.
  • POLYGONInclude only polygon classes from the network analysis layer.
  • NULLInclude only tables from the network analysis layer.

(El valor predeterminado es ANY)

String
Valor de retorno
Tipo de datosExplicación
Dictionary

A dictionary whose keys are the network analysis class names and values are the layer names that reference the network analysis classes from the network analysis layer.

Muestra de código

GetNAClassNames example (workflow)

This example shows how to generate one-, two-, and three-minute service area polygons around fire stations and export the service areas as a feature class in a geodatabase. It illustrates how the GetNAClassNames function can be used to derive values that can be used as input for other ArcPy functions.

# Name: GetNAClassNames_01.py
# Description: Create service areas around fire stations. Use GetNAClassNames
#              to find the names of the Service Area sublayers.
# Requirements: Network Analyst Extension

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

try:

    #Check out the Network Analyst extension license

    #Set environment settings
    output_dir = "C:/Data"
    #The NA layer's data will be saved to the workspace specified here
    env.workspace = os.path.join(output_dir, "Output.gdb")
    env.overwriteOutput = True

    #Set local variables
    input_gdb = "C:/Data/SanFrancisco.gdb"
    network = os.path.join(input_gdb, "Transportation", "Streets_ND")
    facilities = os.path.join(input_gdb, "Analysis", "FireStations")  
    output_polygons = os.path.join(output_dir, "Output.gdb",
                                                    "FireStationServiceAreas")
    
    #Make a new service area layer
    SA_layer_object = arcpy.na.MakeServiceAreaAnalysisLayer(network,
                                                    "FireStationServiceAreas",
                                                    "Driving Time",
                                                    "FROM_Facilities",
                                                    [1, 2, 3]).getOutput(0)
    
    #Get the network analysis class names from the service area layer
    na_classes = arcpy.na.GetNAClassNames(SA_layer_object)
    
    #Load fire stations as facilities
    arcpy.na.AddLocations(SA_layer_object, na_classes["Facilities"], facilities)
    
    #Solve the service area layer
    arcpy.na.Solve(SA_layer_object)
    
    #Get the polygons sublayer from the service area layer
    polygonsSublayer = SA_layer_object.listLayers(na_classes["SAPolygons"])[0]
    
    #Export the polygons sublayer as a feature class
    arcpy.management.CopyFeatures(polygonsSublayer, output_polygons)
    
    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))

Temas relacionados