Make Closest Facility 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 network cost.

Usage

Syntax

MakeClosestFacilityLayer_na (in_network_dataset, out_network_analysis_layer, impedance_attribute, {travel_from_to}, {default_cutoff}, {default_number_facilities_to_find}, {accumulate_attribute_name}, {UTurn_policy}, {restriction_attribute_name}, {hierarchy}, {hierarchy_settings}, {output_path_shape})
ParameterExplanationData Type
in_network_dataset

The network dataset on which the closest facility analysis will be performed.

Network Dataset Layer
out_network_analysis_layer

Name of the closest facility network analysis layer to create.

String
impedance_attribute

The cost attribute to be used as impedance in the analysis.

String
travel_from_to
(Optional)

Specifies the direction of travel between facilities and incidents.

  • TRAVEL_FROMDirection of travel is from facilities to incidents
  • TRAVEL_TODirection of travel is from incidents to facilities

Using this option can find different facilities on a network with one-way restrictions and different impedances based on direction of travel. For instance, a facility may be a 10-minute drive from the incident while traveling from the incident to the facility, but while traveling from the facility to the incident, it may be a 15-minute journey because of different travel time in that direction.

Fire departments commonly use the TRAVEL_FROM setting since they are concerned with the time it takes to travel from the fire station (facility) to the location of the emergency (incident). A retail store (facility) is more concerned with the time it takes the shoppers (incidents) to reach the store; therefore, stores commonly use the TRAVEL_TO option.

String
default_cutoff
(Optional)

Default impedance value at which to stop searching for facilities for a given incident. The default can be overridden by specifying the cutoff value on incidents when TRAVEL_TO option is used or by specifying the cutoff value on facilities when TRAVEL_FROM option is used.

Double
default_number_facilities_to_find
(Optional)

Default number of closest facilities to find per incident. The default can be overridden by specifying a value for the TargetFacilityCount property on the incidents.

Long
accumulate_attribute_name
[accumulate_attribute_name,...]
(Optional)

List of cost attributes to be accumulated during analysis. These accumulation attributes are purely for reference; the solver only uses the cost attribute specified by the Impedance attribute parameter to calculate the route.

For each cost attribute that is accumulated, a Total_[Impedance] property is added to the routes that are output by the solver.

String
UTurn_policy
(Optional)

Restrict or permit U-turns at junctions that could occur during network traversal between stops.

  • ALLOW_UTURNSU-turns are permitted at junctions with any number of adjacent edges.
  • NO_UTURNSU-turns are prohibited at all junctions. Note, however, that U-turns are still permitted at network locations even when this setting is chosen; however, you can set the individual network locations' CurbApproach property to prohibit U-turns.
  • ALLOW_DEAD_ENDS_ONLYU-turns are prohibited at all junctions, except those that have only one adjacent edge (a dead end).
  • ALLOW_DEAD_ENDS_AND_INTERSECTIONS_ONLYU-turns are prohibited at junctions where exactly two adjacent edges meet but are permitted at intersections (any junction with three or more adjacent edges) or dead ends. (junctions with exactly one adjacent edge)
String
restriction_attribute_name
[restriction_attribute_name,...]
(Optional)

List of restriction attributes to apply during the analysis.

String
hierarchy
(Optional)
  • USE_HIERARCHY Use the hierarchy attribute for the analysis. Using a hierarchy results in the solver preferring higher-order edges to lower-order edges. Hierarchical solves are faster, and they can be used to simulate the preference of a driver who chooses to travel on freeways over local roads when possible—even if that means a longer trip. This option is valid only if the input network dataset has a hierarchy attribute.
  • NO_HIERARCHYDo not use the hierarchy attribute for the analysis. Not using a hierarchy yields an exact route for the network dataset.

The parameter is not used if a hierarchy attribute is not defined on the network dataset used to perform the analysis. In such cases, use "#" as the parameter value.

Boolean
hierarchy_settings
(Optional)

LegacyLegacy:

Prior to version 10, this parameter allowed you to change the hierarchy ranges for your analysis from the default hierarchy ranges established in the network dataset. At version 10, this parameter is no longer supported and should be specified as an empty string. If you wish to change the hierarchy ranges for your analysis, update the default hierarchy ranges in the network dataset.

Network Analyst Hierarchy Settings
output_path_shape
(Optional)

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

  • TRUE_LINES_WITH_MEASURESThe output routes will have the exact shape of the underlying network sources. Furthermore, 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.
  • TRUE_LINES_WITHOUT_MEASURESThe output routes will have the exact shape of the underlying network sources.
  • STRAIGHT_LINESThe output route shape will be a single straight line between each of the incident-facility pair.
  • NO_LINESNo shape will be generated for the output routes.

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

String

Code Sample

MakeClosestFacilityLayer example 1 (Python window)

Execute the tool using only the required parameters

import arcpy
arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/SanFrancisco.gdb"
arcpy.MakeClosestFacilityLayer_na("Transportation/Streets_ND",
                                  "ClosestFireStations","Minutes")
MakeClosestFacilityLayer example 2 (Python window)

Execute the tool using all parameters

import arcpy
arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/SanFrancisco.gdb"
arcpy.MakeClosestFacilityLayer_na("Transportation/Streets_ND",
                                  "ClosestHospitals","Minutes","TRAVEL_TO",5,3,
                                  ["Meters","Minutes"],"ALLOW_UTURNS",
                                  ["Oneway"],"USE_HIERARCHY","",
                                  "TRUE_LINES_WITH_MEASURES")
MakeClosestFacilityLayer example 3 (workflow)

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

# Name: MakeClosestFacilityLayer_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 
# Author: ESRI

#Import system modules
import arcpy
from arcpy import env

try:
    #Check out the Network Analyst extension license
    arcpy.CheckOutExtension("Network")

    #Set environment settings
    env.workspace = "C:/data/Paris.gdb"
    env.overwriteOutput = True
    
    #Set local variables
    inNetworkDataset = "Transportation/ParisMultimodal_ND"
    outNALayer = "ClosestWarehouse"
    impedanceAttribute = "Drivetime"
    accumulateAttributeName = ["Meters"]
    inFacilities = "Analysis/Warehouses"
    inIncidents = "Analysis/Stores"
    fieldMappings = "Name NOM #"
    outLayerFile = "C:/data/output" + "/" + outNALayer + ".lyr"
    
    #Create a new closest facility analysis layer. Apart from finding the drive 
    #time to the closest warehouse, we also want to find the total distance. So
    #we will accumulate the "Meters" impedance attribute.
    arcpy.MakeClosestFacilityLayer_na(inNetworkDataset,outNALayer,
                                      impedanceAttribute,"TRAVEL_TO","",1,
                                      accumulateAttributeName,"NO_UTURNS")
    
    #Load the warehouses as Facilities using the default field mappings and 
    #search tolerance
    arcpy.AddLocations_na(outNALayer,"Facilities",inFacilities,"","")
    
    #Load the Stores as Incidents. Map the Name property from the NOM field
    arcpy.AddLocations_na(outNALayer,"Incidents",inIncidents,fieldMappings,"")
    
    #Solve the closest facility layer
    arcpy.Solve_na(outNALayer)
    
    #Save the solved closest facility layer as a layer file on disk with 
    #relative paths
    arcpy.SaveToLayerFile_management(outNALayer,outLayerFile,"RELATIVE")
    
    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)

Environments

Related Topics

Licensing Information

ArcView: Requires Network Analyst
ArcEditor: Requires Network Analyst
ArcInfo: Requires Network Analyst

Published 6/7/2010