Make Closest Facility Analysis Layer (Network Analyst)

Summary

Makes a closest facility network analysis layer and sets its analysis properties. A closest facility analysis layer is useful in determining the closest facility or facilities to an incident based on a specified travel mode. The layer can be created using a local network dataset or using a service hosted online or in a portal.

Parameters

LabelExplanationData 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 between facilities and incidents.

The direction of travel may influence the facilities found if the network contains one-way streets or impedances based on the direction of travel. For instance, it might take 10 minutes to drive from a particular incident to a particular facility, but the journey might take 15 minutes traveling in the other direction, from the facility to the incident, because of one-way streets or different traffic conditions.

  • Toward facilitiesDirection of travel is from incidents to facilities. Retail stores commonly use this setting, since they are concerned with the time it takes the shoppers (incidents) to reach the store (facility). This is the default.
  • Away from facilitiesDirection of travel is from facilities to incidents. Fire departments commonly use this setting, since they are concerned with the time it takes to travel from the fire station (facility) to the location of the emergency (incident).
String
Cutoff
(Optional)

The impedance value at which to stop searching for facilities for a given incident in the units of the impedance attribute used by your chosen Travel Mode. This cutoff can be overridden on a per-incident basis by specifying individual cutoff values in the incidents sublayer when the Travel Direction is Toward facilities or on a per-facility basis by specifying individual cutoff values in the facilities sublayer when the Travel Direction is Away from facilities. By default, no cutoff is used for the analysis.

Double
Number of Facilities to Find
(Optional)

The number of closest facilities to find per incident. This default can be overridden by specifying an individual value for the TargetFacilityCount property in the incidents sublayer. The default number of facilities to find is one.

Long
Time of Day
(Optional)

The time and date at which the routes should begin or end. The interpretation of this value depends on whether Time of Day Usage is set to be the start time or the end time of the route.

If you have chosen a traffic-based impedance attribute, the solution will be generated given dynamic traffic conditions at the time of day specified here. A date and time can be specified as 5/14/2012 10:30 AM.

Instead of using a particular date, a day of the week can be specified using the following dates:

  • Today—12/30/1899
  • Sunday—12/31/1899
  • Monday—1/1/1900
  • Tuesday—1/2/1900
  • Wednesday—1/3/1900
  • Thursday—1/4/1900
  • Friday—1/5/1900
  • Saturday—1/6/1900

Date
Time Zone
(Optional)

The time zone of the Time of Day parameter.

  • Local time at locationsThe Time of Day parameter refers to the time zone in which the facilities or incidents are located. This is the default.
    • If Time of Day Usage is set to Start time and Travel Direction is Away from facilities, this is the time zone of the facilities.
    • If Time of Day Usage is set to Start time and Travel Direction is Towards facilities, this is the time zone of the incidents.
    • If Time of Day Usage is set to End time and Travel Direction is Away from facilities, this is the time zone of the incidents.
    • If Time of Day Usage is set to End time and Travel Direction is Towards facilities, this is the time zone of the facilities.
  • UTCThe Time of Day parameter refers to Coordinated Universal Time (UTC). Choose this option if you want to find what's nearest for a specific time, such as now, but aren't certain in which time zone the facilities or incidents will be located.
String
Time of Day Usage
(Optional)

Specifies whether the value of the Time of Day parameter represents the arrival or departure time for the route or routes.

  • Start timeTime of Day is interpreted as the departure time from the facility or incident. This is the default.When this setting is chosen, Time of Day indicates the solver should find the best route given a departure time.
  • End timeTime of Day is interpreted as the arrival time at the facility or incident. This option is useful if you want to know what time to depart from a location so you arrive at the destination at the time specified in Time of Day.
String
Line Shape
(Optional)

Specifies the shape type for the route features that are output by the analysis.

No matter which output shape type is chosen, the best route is always determined by the network impedance, never Euclidean distance. This means that only the route shapes are different, not the underlying traversal of the network.

  • Along networkThe output routes will have the exact shape of the underlying network sources. The output includes route measurements for linear referencing. The measurements increase from the first stop and record the cumulative impedance to reach a given position.
  • No linesNo shape will be generated for the output routes.
  • Straight linesThe output route shape will be a single straight line between the stops.
String
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 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
Generate Directions on Solve
(Optional)

Specifies whether directions will be generated when running the analysis.

  • Checked—Indicates that the turn-by-turn directions will be generated on solve.
  • Unchecked—Indicates that the turn-by-turn directions will not be generated on solve. This is the default.

For an analysis in which generating turn-by-turn directions is not needed, leaving this option unchecked will considerably reduce the time it takes to solve the analysis.

Boolean
Ignore Invalid Locations at Solve Time
(Optional)

Specifies whether invalid input locations will be ignored. Typically, locations are invalid if they cannot be located on the network. When invalid locations are ignored, the solver will skip them and attempt to perform the analysis using the remaining locations.

  • Checked—Invalid input locations will be ignored and only valid locations will be used. This is the default.
  • Unchecked—All input locations will be used. Invalid locations will cause the analysis to fail.
Boolean

Derived Output

LabelExplanationData Type
Network Analyst Layer

The newly created network analysis layer.

Network Analyst Layer

arcpy.na.MakeClosestFacilityAnalysisLayer(network_data_source, {layer_name}, {travel_mode}, {travel_direction}, {cutoff}, {number_of_facilities_to_find}, {time_of_day}, {time_zone}, {time_of_day_usage}, {line_shape}, {accumulate_attributes}, {generate_directions_on_solve}, {ignore_invalid_locations})
NameExplanationData 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 between facilities and incidents.

  • TO_FACILITIESDirection of travel is from incidents to facilities. Retail stores commonly use this setting, since they are concerned with the time it takes the shoppers (incidents) to reach the store (facility). This is the default.
  • FROM_FACILITIESDirection of travel is from facilities to incidents. Fire departments commonly use this setting, since they are concerned with the time it takes to travel from the fire station (facility) to the location of the emergency (incident).

The direction of travel may influence the facilities found if the network contains one-way streets or impedances based on the direction of travel. For instance, it might take 10 minutes to drive from a particular incident to a particular facility, but the journey might take 15 minutes traveling in the other direction, from the facility to the incident, because of one-way streets or different traffic conditions.

String
cutoff
(Optional)

The impedance value at which to stop searching for facilities for a given incident in the units of the impedance attribute used by your chosen travel_mode. This cutoff can be overridden on a per-incident basis by specifying individual cutoff values in the incidents sublayer when travel_direction = 'TO_FACILITIES' or on a per-facility basis by specifying individual cutoff values in the facilities sublayer when travel_direction = 'FROM_FACILITIES'By default, no cutoff is used for the analysis.

Double
number_of_facilities_to_find
(Optional)

The number of closest facilities to find per incident. This default can be overridden by specifying an individual value for the TargetFacilityCount property in the incidents sublayer. The default number of facilities to find is one.

Long
time_of_day
(Optional)

The time and date at which the routes should begin or end. The interpretation of this value depends on whether time_of_day_usage is set to be the start time or the end time of the route.

If you have chosen a traffic-based impedance attribute, the solution will be generated given dynamic traffic conditions at the time of day specified here. A date and time can be specified as 5/14/2012 10:30 AM.

Instead of using a particular date, a day of the week can be specified using the following dates:

  • Today—12/30/1899
  • Sunday—12/31/1899
  • Monday—1/1/1900
  • Tuesday—1/2/1900
  • Wednesday—1/3/1900
  • Thursday—1/4/1900
  • Friday—1/5/1900
  • Saturday—1/6/1900

Date
time_zone
(Optional)

Specifies the time zone for the time_of_day parameter.

  • LOCAL_TIME_AT_LOCATIONSThe time_of_day parameter refers to the time zone in which the facilities or incidents are located. This is the default.
    • If time_of_day_usage is set to START_TIME and travel_direction is FROM_FACILITIES, this is the time zone of the facilities.
    • If time_of_day_usage is set to START_TIME and travel_direction is TO_FACILITIES, this is the time zone of the incidents.
    • If time_of_day_usage is set to END_TIME and travel_direction is FROM_FACILITIES, this is the time zone of the incidents.
    • If time_of_day_usage is set to END_TIME and travel_direction is TO_FACILITIES, this is the time zone of the facilities.
  • UTCThe time_of_day parameter refers to Coordinated Universal Time (UTC). Choose this option if you want to find what's nearest for a specific time, such as now, but aren't certain in which time zone the facilities or incidents will be located.
String
time_of_day_usage
(Optional)

Specifies whether the value of the time_of_day parameter represents the arrival or departure time for the route or routes.

  • START_TIMEtime_of_day is interpreted as the departure time from the facility or incident. This is the default.When this setting is chosen, time_of_day indicates the solver should find the best route given a departure time.
  • END_TIMEtime_of_day is interpreted as the arrival time at the facility or incident. This option is useful if you want to know what time to depart from a location so you arrive at the destination at the time specified in time_of_day.
String
line_shape
(Optional)

Specifies the shape type for the route features that are output by the analysis.

No matter which output shape type is chosen, the best route is always determined by the network impedance, never Euclidean distance. This means that only the route shapes are different, not the underlying traversal of the network.

  • ALONG_NETWORKThe output routes will have the exact shape of the underlying network sources. The output includes route measurements for linear referencing. The measurements increase from the first stop and record the cumulative impedance to reach a given position.
  • NO_LINESNo shape will be generated for the output routes.
  • STRAIGHT_LINESThe output route shape will be a single straight line between the stops.
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 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
generate_directions_on_solve
(Optional)

Specifies whether directions will be generated when running the analysis.

  • DIRECTIONS Indicates that the turn-by-turn directions will be generated on solve.
  • NO_DIRECTIONSIndicates that the turn-by-turn directions will not be generated on solve. This is the default.

For an analysis in which generating turn-by-turn directions is not needed, use the default option NO_DIRECTIONS to considerably reduce the time it takes to solve the analysis.

Boolean
ignore_invalid_locations
(Optional)

Specifies whether invalid input locations will be ignored. Typically, locations are invalid if they cannot be located on the network. When invalid locations are ignored, the solver will skip them and attempt to perform the analysis using the remaining locations.

  • SKIPInvalid input locations will be ignored and only valid locations will be used. This is the default.
  • HALTAll input locations will be used. Invalid locations will cause the analysis to fail.
Boolean

Derived Output

NameExplanationData Type
out_network_analysis_layer

The newly created network analysis layer.

Network Analyst Layer

Code sample

MakeClosestFacilityAnalysisLayer example 1 (Python window)

Execute the tool using only the required parameters.

network = "C:/Data/SanFrancisco.gdb/Transportation/Streets_ND"
arcpy.na.MakeClosestFacilityAnalysisLayer(network, "ClosestFireStations")
MakeClosestFacilityAnalysisLayer example 2 (Python window)

Execute the tool using all parameters.

network = "C:/Data/SanFrancisco.gdb/Transportation/Streets_ND"
arcpy.na.MakeClosestFacilityAnalysisLayer(network, "ClosestHospitals",
                                "Driving Time", "TO_FACILITIES", 5, 3,
                                "1/1/1900 9:00 AM", "UTC", "START_TIME",
                                "ALONG_NETWORK", ["Meters", "TravelTime"])
MakeClosestFacilityAnalysisLayer example 3 (stand-alone script)

The following stand-alone Python script demonstrates how the MakeClosestFacilityAnalysisLayer tool can be used to find the closest warehouse from the store locations.

# Name: MakeClosestFacilityAnalysisLayer_Workflow.py
# Description: Find the closest warehouse from the store locations and save the
#              results to a layer file on disk.
# 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/Paris.gdb"
    network = os.path.join(input_gdb, "Transportation", "ParisMultimodal_ND")
    layer_name = "ClosestWarehouse"
    travel_mode = "Driving Time"
    facilities = os.path.join(input_gdb, "Analysis", "Warehouses")
    incidents = os.path.join(input_gdb, "Analysis", "Stores")
    output_layer_file = os.path.join(output_dir, layer_name + ".lyrx")

    #Create a new closest facility analysis layer. 
    result_object = arcpy.na.MakeClosestFacilityAnalysisLayer(network,
                                    layer_name, travel_mode, "TO_FACILITIES",
                                    number_of_facilities_to_find=1)

    #Get the layer object from the result object. The closest facility layer can
    #now be referenced using the layer object.
    layer_object = result_object.getOutput(0)

    #Get the names of all the sublayers within the closest facility layer.
    sublayer_names = arcpy.na.GetNAClassNames(layer_object)
    #Stores the layer names that we will use later
    facilities_layer_name = sublayer_names["Facilities"]
    incidents_layer_name = sublayer_names["Incidents"]

    #Load the warehouses as Facilities using the default field mappings and
    #search tolerance
    arcpy.na.AddLocations(layer_object, facilities_layer_name,
                            facilities, "", "")

    #Load the stores as Incidents. Map the Name property from the NOM field
    #using field mappings
    field_mappings = arcpy.na.NAClassFieldMappings(layer_object,
                                                    incidents_layer_name)
    field_mappings["Name"].mappedFieldName = "NOM"
    arcpy.na.AddLocations(layer_object, incidents_layer_name, incidents,
                          field_mappings, "")

    #Solve the closest facility layer
    arcpy.na.Solve(layer_object)

    #Save the solved closest facility 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))

Environments

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes