Zusammenfassung
Provides a Python dictionary of NAClassFieldMap objects that are used to map field names or set default values for the properties of a network analysis class within a network analysis layer. The dictionary keys are the network analysis class property names, and the values are the NAClassFieldMap objects.
Auswertung
The NAClassFieldMappings object or its string representation is used as input to the field_mappings parameter in the Add Locations geoprocessing tool. The NAClassFieldMap objects contained within the NAClassFieldMappings object provide access to get or set the default value and the mapped field name associated with each property of the network analysis class.
Syntax
NAClassFieldMappings (network_analyst_layer, sub_layer_name, {use_location_fields}, {list_candidate_fields})
Parameter | Erklärung | Datentyp |
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 if a given Layer object is a network analysis layer. | Layer |
sub_layer_name | The sublayer name for which the field mappings are to be created. The name must be valid for the particular network analysis layer type. For a given network analysis layer, the sublayer name can be determined using the GetNAClassNames function. | String |
use_location_fields | Specifies whether to create the field mappings for the network location properties along with other properties. (Der Standardwert ist False) | Boolean |
list_candidate_fields [list_candidate_fields,...] | A list of Field objects that are used to generate the mapped field names. The argument value can be obtained from a given feature class or table using the ListFields function. If the argument is not specified, then the field mappings are created with only the default values for the appropriate properties. (Der Standardwert ist None) | Field |
Codebeispiel
NAClassFieldMappings Example 1 (Python window)
The following script shows how to load fire stations as facilities into an existing service area layer and specify a delay of 10 minutes when loading the facilities using the NAClassFieldMappings object. It assumes that a service area network analysis layer called Fire Stations Coverage, created from the tutorial network dataset for the San Francisco region, and a feature layer called FireStations are already added to an existing map document.
#Get the service area layer called "Fire Stations Coverage" from the table of contents
saLayer = arcpy.mapping.Layer("Fire Stations Coverage")
#Get the list of fields from the FireStations feature layer in the table of contents
fields = arcpy.ListFields("FireStations")
#Get the facilities sublayer name from the service area layer. Note that we are not
#using a string called "Facilities" because the sublayer name can be
#different if using ArcGIS on a non-english operating system.
facilitiesSubLayerName = arcpy.na.GetNAClassNames(saLayer)["Facilities"]
#Create a field mappings object for facilities sublayer based on the fields from
#FireStations layer
fieldMappings = arcpy.na.NAClassFieldMappings(saLayer, facilitiesSubLayerName,
False, fields)
#Get the field map corresponding to the "Attr_TravelTime" property of facilities
fieldMap = fieldMappings["Attr_TravelTime"]
#Set a delay of 10 minutes for the facilities
fieldMap.defaultValue = 10
#Load the fire stations as service area facilities using the field mappings
arcpy.na.AddLocations(saLayer, facilitiesSubLayerName, "FireStations", fieldMappings)
NAClassFieldMappings Example 2 (workflow)
The example shows how to find the best route between some store locations considering weather conditions as slowdown areas. It illustrates how to use the NAClassFieldMappings object while loading the weather polygons as polygon barriers and store locations as stops using the Add Locations tool.
import arcpy
#Set up the environment
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("network")
#Set up variables
networkDataset = "C:/Data/SanFrancisco.gdb/Transportation/Streets_ND"
polygonBarriers = "C:/Data/WeatherSlowDownAreas.shp"
stops = "C:/Data/SanFrancisco.gdb/Analysis/Stores"
impedanceAttribute = "TravelTime"
outputLayer = "C:/Data/WeatherRoute.lyr"
#Create a new route layer
routeLayer = arcpy.na.MakeRouteLayer(networkDataset, "WeatherRoute",
impedanceAttribute).getOutput(0)
#Get na class names based on the layer
naClasses = arcpy.na.GetNAClassNames(routeLayer, "INPUT")
#Create field mappings for loading barriers as scaled cost polygon barriers
#with a slow down of 40%
fieldMappings = arcpy.na.NAClassFieldMappings(routeLayer,
naClasses["PolygonBarriers"])
fieldMappings["BarrierType"].defaultValue = 1
fieldMappings["Attr_" + impedanceAttribute].defaultValue = 1.4
#Load weather polygons as slow down barriers
arcpy.na.AddLocations(routeLayer, naClasses["PolygonBarriers"],
polygonBarriers, fieldMappings)
#get a list of field objects from the stores feature class
storeFields = arcpy.ListFields(stops)
#Create field mappings for loading stops based on the field names from the stores
stopsFieldMappings = arcpy.na.NAClassFieldMappings(routeLayer, naClasses["PolygonBarriers"],
False, storeFields)
#Load stops using the field mappings
arcpy.na.AddLocations(routeLayer, naClasses["Stops"], stops, stopsFieldMappings)
#Solve the route
arcpy.na.Solve(routeLayer)
#Save the solved layer as a layer file
arcpy.management.SaveToLayerFile(routeLayer, outputLayer)
arcpy.AddMessage("Completed")