Zusammenfassung
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.
Diskussion
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.
Syntax
GetNAClassNames (network_analyst_layer, {naclass_edit_type}, {nalocation_type}, {shape_type})
Parameter | Erläuterung | Datentyp |
network_analyst_layer | A network analysis layer object or layer name. | 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:
(Der Standardwert ist 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:
(Der Standardwert ist 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:
(Der Standardwert ist ANY) | String |
Datentyp | Erläuterung | ||||||||||||
Dictionary | A dictionary whose keys are the network analysis class names and whose values are the layer names that reference the network analysis classes from the network analysis layer. The class name keys for each network analysis layer type are shown in the table below.
|
Codebeispiel
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.
Vorversion:
Mit der Funktion GetNASublayer kann nach den Sublayern eines Netzwerkanalyse-Layers gesucht werden. Sie wurde in ArcGIS Pro 2.7 eingeführt. In älteren Softwareversionen bestand die beste Möglichkeit, ein Sublayer-Objekt eines Netzwerkanalyse-Layers abzurufen, in der Verwendung der listLayers-Methode des Layer-Objekts der Netzwerkanalyse mit dem Namen des Sublayers als Platzhalter.
# 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
import os
try:
# Check out Network Analyst license if available. Fail if the Network Analyst license is not available.
if arcpy.CheckExtension("network") == "Available":
arcpy.CheckOutExtension("network")
else:
raise arcpy.ExecuteError("Network Analyst Extension license is not available.")
# Set environment settings
output_dir = "C:/Data"
# The NA layer's data will be saved to the workspace specified here
arcpy.env.workspace = os.path.join(output_dir, "Output.gdb")
arcpy.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 = arcpy.na.GetNASublayer(SA_layer_object, "SAPolygons")
# 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))