Summary
Makes a service area network analysis layer and sets its analysis properties. A service area analysis layer is useful in determining the area of accessibility within a given cutoff cost from a facility location. The layer can be created using a local network dataset or using a routing service hosted online or in a portal.
Usage
After creating the analysis layer with this tool, you can add network analysis objects to it using the Add Locations tool, solve the analysis using the Solve tool, and save the results on disk using the Save To Layer File tool.
When using this tool in geoprocessing models, if the model is run as a tool, the output network analysis layer must be made a model parameter; otherwise, the output layer is not added to the contents of the map.
In ArcGIS Pro, network analysis layer data is stored on disk in file geodatabase feature classes. When creating a network analysis layer in a project, the layer's data will be created in a new feature dataset in the Current Workspace environment. When creating a network analysis layer in a Python script, you must first explicitly set the workspace environment to a file geodatabase where you want the layer's data to be stored using arcpy.env.workspace = "<path to file gdb>". When the layer is created, a new feature dataset containing the appropriate sublayer feature classes will be added to this file geodatabase.
Syntax
MakeServiceAreaAnalysisLayer(network_data_source, {layer_name}, {travel_mode}, {travel_direction}, {cutoffs}, {time_of_day}, {time_zone}, {output_type}, {polygon_detail}, {geometry_at_overlaps}, {geometry_at_cutoffs}, {polygon_trim_distance}, {exclude_sources_from_polygon_generation}, {accumulate_attributes})
Parameter | Explanation | Data Type |
network_data_source | The network dataset or service on which the network analysis will be performed. Use the portal URL for a service. | Network Dataset Layer;String |
layer_name (Optional) | The name of the network analysis layer to create. | String |
travel_mode (Optional) | The name of the travel mode to use in the analysis. The travel mode represents a collection of network settings, such as travel restrictions and U-turn policies, that determine how a pedestrian, car, truck, or other medium of transportation moves through the network. Travel modes are defined on your network data source. An arcpy.na.TravelMode object and a string containing the valid JSON representation of a travel mode can also be used as input to the parameter. | String |
travel_direction (Optional) | Specifies the direction of travel to or from the facilities.
Using this parameter can result in different service areas on a network with one-way restrictions and different impedances based on direction of travel. The service area for a pizza delivery store, for example, should be created away from the facility, whereas the service area of a hospital should be created toward the facility. | String |
cutoffs [cutoffs,...] (Optional) |
The extent of the service area to be calculated in the units of the impedance attribute used by your selected travel mode. For example, when analyzing driving time, a cutoff value of 10 means that the resulting service area will represent the area reachable within a 10-minute drive time. Multiple cutoffs can be set to create concentric service areas. For example, to find 2-, 3-, and 5-minute service areas for the same facility, specify 2, 3, and 5 as the values for this parameter. This default cutoff value can be overridden on a per-facility basis by specifying individual break values in the facilities sublayer. | Double |
time_of_day (Optional) | The time to depart from or arrive at the facilities of the service area layer. The interpretation of this value as a departure or arrival time depends on whether travel is away from or toward the facilities.
The time_of_day parameter is most useful for finding the roads that can be reached based on a travel mode that uses an impedance attribute that varies with the time of the day, such as one based on dynamic traffic conditions. Solving the same analysis using different time_of_day values allows you to see how a facility's reach changes over time. For example, the five-minute service area around a fire station may start out large in the early morning, diminish during the morning rush hour, grow in the late morning, and so on throughout the day. A date and time can be specified as 10/21/2015 10:30 AM. Instead of using a particular date, a day of the week can be specified using the following dates:
| Date |
time_zone (Optional) |
Specifies the time zone for the time of day parameter.
| String |
output_type (Optional) | Specifies the type of output to be generated. Service area output can be line features representing the roads reachable before the cutoffs are exceeded or the polygon features encompassing these lines (representing the reachable area).
The Lines and Polygons and lines output types are not available if the network data source is a service on a version of Portal for ArcGIS that does not support line generation. | String |
polygon_detail (Optional) | Specifies the level of detail of the output polygons.
If your analysis includes an urban area with a grid-like street network, the difference between generalized and standard polygons will be minimal. However, for mountain and rural roads, the standard and detailed polygons may present significantly more accurate results than generalized polygons. | String |
geometry_at_overlaps (Optional) | Specifies the behavior of service-area output from multiple facilities in relation to one another.
| String |
geometry_at_cutoffs (Optional) | Specifies the behavior of service area output for a single facility when multiple cutoff values are specified. This parameter does not apply to line output.
| String |
polygon_trim_distance (Optional) | The service area polygon trim distance. The polygon trim distance is the distance the service area polygon will extend from the road when no other reachable roads are nearby, similar to a line buffer size. This is useful when the network is sparse and you don't want the service area to cover large areas where there are no features. This parameter includes a value and units for the distance. The default value is 100 meters. | Linear Unit |
exclude_sources_from_polygon_generation [exclude_sources_from_polygon_generation,...] (Optional) | The network dataset edge sources that will be excluded when generating service area polygons. Polygons will not be generated around the excluded sources, even though they are traversed in the analysis. Excluding a network source from service area polygons does not prevent those sources from being traversed. Excluding sources from service area polygons only influences the polygon shape of the service areas. To prevent traversal of a given network source, you must create an appropriate restriction when defining your network dataset. This is useful if you have some network sources that you don't want to be included in the polygon generation because they create less accurate polygons or are inconsequential for the service area analysis. For example, while creating a walk-time service area in a multimodal network that includes streets and metro lines, you should choose to exclude the metro lines from polygon generation. Although the traveler can use the metro lines, they cannot stop partway along a metro line and enter a nearby building. Instead, they must travel the full length of the metro line, exit the metro system at a station, then use the streets to walk to the building. It would be inaccurate to generate a polygon feature around a metro line. This parameter is not available when the output geometry types do not include polygons, there are less than two edge sources in the network, the network data source is an ArcGIS Online service, or the network data source is a service on a version of Portal for ArcGIS which does not support excluding sources. | String |
accumulate_attributes [accumulate_attributes,...] (Optional) | A list of cost attributes to be accumulated during analysis. These accumulated attributes are for reference only; the solver only uses the cost attribute used by your designated travel mode when solving the analysis. For each cost attribute that is accumulated, a Total_[Impedance] property is populated in the network analysis output features. This parameter is not available if the analysis layer is not configured to output lines, the network data source is an ArcGIS Online service, or the network data source is a service on a version of Portal for ArcGIS that does not support accumulation. | String |
Derived Output
Name | Explanation | Data Type |
out_network_analysis_layer | The newly created network analysis layer. | Network Analyst Layer |
Code sample
Execute the tool using only the required parameters.
network = "C:/Data/SanFrancisco.gdb/Transportation/Streets_ND"
arcpy.na.MakeServiceAreaAnalysisLayer(network, "FireStationCoverage")
Execute the tool using all parameters.
network = "C:/Data/Paris.gdb/Transportation/ParisMultimodal_ND"
arcpy.na.MakeServiceAreaAnalysisLayer(network, "WarehouseCoverage",
"Driving Time", "FROM_FACILITIES", [5, 10, 15],
"1/1/1900 9:00 AM", "UTC", "POLYGONS",
"STANDARD", "DISSOLVE", "RINGS", "100 meters",
["Metro_Lines", "Transfer_Stations",
"Transfer_Street_Station"], ["Meters",
"DriveTime"])
The following stand-alone Python script demonstrates how the MakeServiceAreaAnalysisLayer tool can be used to generate a 1-, 2-, and 3-minute service area around fire stations.
# Name: MakeServiceAreaAnalysisLayer_Workflow.py
# Description: Generate 1-,2-,3- minute service areas around fire stations and
# save the results to a layer file on disk. The service area
# polygons can be used to visualize the areas that do not have
# adequate coverage from the fire stations
# Requirements: Network Analyst Extension
#Import system modules
import arcpy
from arcpy import env
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
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")
layer_name = "FireStationCoverage"
travel_mode = "Driving Time"
facilities = os.path.join(input_gdb, "Analysis", "FireStations")
output_layer_file = os.path.join(output_dir, layer_name + ".lyrx")
#Create a new service area layer. We wish to generate the service area
#polygons as rings, so that we can easily visualize the coverage for any
#given location. We also want overlapping polygons so we can determine the
#number of fire stations that cover a given location. We will specify these
#options while creating the new service area layer.
result_object = arcpy.na.MakeServiceAreaAnalysisLayer(network, layer_name,
travel_mode, "FROM_FACILITIES", [1, 2, 3],
polygon_detail="HIGH",
geometry_at_overlaps="OVERLAP",
geometry_at_cutoffs="RINGS")
#Get the layer object from the result object. The service layer can now be
#referenced using the layer object.
layer_object = result_object.getOutput(0)
#Get the names of all the sublayers within the service area layer.
sublayer_names = arcpy.na.GetNAClassNames(layer_object)
#Stores the layer names that we will use later
facilities_layer_name = sublayer_names["Facilities"]
#Load the fire stations as facilities using default field mappings and
#default search tolerance
arcpy.na.AddLocations(layer_object, facilities_layer_name, facilities, "",
"")
#Solve the service area layer
arcpy.na.Solve(layer_object)
#Save the solved service area layer as a layer file on disk
layer_object.saveACopy(output_layer_file)
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 occurred on line %i" % tb.tb_lineno)
print(str(e))
This example shows how to create service areas around facilities for multiple times of the day as well as how to port fields from the input features to the output features and append output polygons to an existing feature class.
# Name: MakeServiceAreaAnalysisLayer_Workflow2.py
# Description: Generate 3-minute service areas around fire stations at several
# times of day to compare coverage differences due to varying
# traffic conditions. Save the results to a feature class on disk.
# Requirements: Network Analyst Extension
#Import system modules
import arcpy
from arcpy import env
import os, datetime
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
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")
layer_name = "FireStationCoverage"
out_featureclass = os.path.join(output_dir, "Output.gdb",
"FireStationCoverage")
travel_mode = "Driving Time"
facilities = os.path.join(input_gdb, "Analysis", "FireStations")
times_of_day = [datetime.datetime(2014, 9, 25, 7, 0, 0),
datetime.datetime(2014, 9, 25, 12, 30, 0),
datetime.datetime(2014, 9, 25, 17, 30, 0),
datetime.datetime(2014, 9, 25, 21, 0, 0)]
#Create a new service area layer.
result_object = arcpy.na.MakeServiceAreaAnalysisLayer(network, layer_name,
travel_mode, "FROM_FACILITIES",
[3], polygon_detail="HIGH",
geometry_at_overlaps="OVERLAP")
#Get the layer object from the result object. The service area layer can
#now be referenced using the layer object.
layer_object = result_object.getOutput(0)
#Get the names of all the sublayers within the service area layer.
sublayer_names = arcpy.na.GetNAClassNames(layer_object)
#Stores the layer names that we will use later
facilities_layer_name = sublayer_names["Facilities"]
polygons_layer_name = sublayer_names["SAPolygons"]
#The input data has a field for FireStationID that we want to transfer to
#our analysis layer. Add the field, and then use field mapping to transfer
#the values.
arcpy.na.AddFieldToAnalysisLayer(layer_object, facilities_layer_name,
"FireStationID", "TEXT")
field_mappings = arcpy.na.NAClassFieldMappings(layer_object,
facilities_layer_name)
field_mappings["FireStationID"].mappedFieldName = "FireStationID"
#Load the fire stations as facilities.
arcpy.na.AddLocations(layer_object, facilities_layer_name, facilities,
field_mappings, "")
# Add fields to the output Polygons sublayer for later use.
arcpy.na.AddFieldToAnalysisLayer(layer_object, polygons_layer_name,
"FireStationID", "TEXT")
arcpy.na.AddFieldToAnalysisLayer(layer_object, polygons_layer_name,
"TimeOfDay", "TEXT")
#Get sublayers to work with later
facilities_sublayer = layer_object.listLayers(facilities_layer_name)[0]
polygons_sublayer = layer_object.listLayers(polygons_layer_name)[0]
#Get the Service Area Layer's solver properties. This can be used to
#set individual properties later without re-creating the layer.
solver_properties = arcpy.na.GetSolverProperties(layer_object)
#Solve the Service Area for each time of day in the time list
for t in times_of_day:
print("Calculating service area for time of day: ", t)
#Use the solver properties to set the time of day for the solve
solver_properties.timeOfDay = t
#Solve the service area layer
arcpy.na.Solve(layer_object)
#Transfer the FireStationID field from the input Facilities to the
#output Polygons
arcpy.management.AddJoin(polygons_sublayer, "FacilityID",
facilities_sublayer, "ObjectID")
#The joined fields are qualified by the feature class name of the joined
#table, so determine the feature class names
field_qualifier_pol = os.path.basename(polygons_sublayer.dataSource)
target_field_name = "%s.FireStationID" % field_qualifier_pol
field_qualifier_fac = os.path.basename(facilities_sublayer.dataSource)
expression = "!%s.FireStationID!" % field_qualifier_fac
arcpy.management.CalculateField(polygons_sublayer, target_field_name,
expression, "PYTHON")
arcpy.management.RemoveJoin(polygons_sublayer)
#Populate the TimeOfDay field in the output feature class
expression = '"' + str(t) + '"'
arcpy.management.CalculateField(polygons_sublayer, "TimeOfDay",
expression, "PYTHON")
#Append the polygons to the output feature class. If this was the first
#solve, create the feature class.
if not arcpy.Exists(out_featureclass):
arcpy.management.CopyFeatures(polygons_sublayer, out_featureclass)
else:
arcpy.management.Append(polygons_sublayer, out_featureclass)
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 occurred on line %i" % tb.tb_lineno)
print(str(e))
Environments
Licensing information
- Basic: Yes
- Standard: Yes
- Advanced: Yes