Summary
Finds one or more facilities closest to an incident based on travel time, distance, or other cost and outputs the best route, chosen facility, and driving directions between the incident and the facility. For example, you can use this tool to find the closest hospital to an accident, the closest police cars to a crime scene, or the closest store to a customer's address.
When finding closest facilities, you can specify how many facilities to find and whether the direction of travel is toward or away from them. If your network dataset supports traffic, you can also specify the time of day to account for travel times for that time and date. For instance, you can use this tool to search for hospitals within a 15-minute drive time of the site of an accident at a given time of day. Any hospitals that take longer than 15 minutes to reach based on the traffic conditions will not be included in the results.
Usage
The tool dialog box groups the various optional parameters into the following six categories to make it easier for you to manage them:
- Advanced Analysis
- Barriers
- Custom Travel Mode
- Network Dataset
- Network Locations
- Output
- Service Capabilities
Syntax
FindClosestFacilities(Incidents, Facilities, Measurement_Units, Network_Dataset, Output_Geodatabase, Output_Routes_Name, Output_Directions_Name, Output_Closest_Facilities_Name, {Number_of_Facilities_to_Find}, {Default_Cutoff}, {Travel_Direction}, {Time_of_Day}, {Time_of_Day_Usage}, {Time_Zone_for_Time_of_Day}, {UTurn_Policy}, {Point_Barriers}, {Line_Barriers}, {Polygon_Barriers}, {Time_Attribute}, {Time_Attribute_Units}, {Distance_Attribute}, {Distance_Attribute_Units}, {Use_Hierarchy_in_Analysis}, {Restrictions}, {Attribute_Parameter_Values}, {Accumulate_Attributes}, {Maximum_Snap_Tolerance}, {Feature_Locator_WHERE_Clause}, {Route_Shape}, {Route_Line_Simplification_Tolerance}, {Populate_Directions}, {Directions_Language}, {Directions_Distance_Units}, {Directions_Style_Name}, {Maximum_Features_Affected_by_Point_Barriers}, {Maximum_Features_Affected_by_Line_Barriers}, {Maximum_Features_Affected_by_Polygon_Barriers}, {Maximum_Facilities}, {Maximum_Facilities_to_Find}, {Maximum_Incidents}, {Force_Hierarchy_Beyond_Distance}, {Save_Output_Network_Analysis_Layer}, {Travel_Mode}, {Overrides}, {Save_Route_Data})
Parameter | Explanation | Data Type |
Incidents | This tool determines which facilities are closest to incidents, and this parameter specifies those incidents. A minimum of one incident is necessary to solve an analysis. When specifying the incidents, you can set properties for each one, such as its name or service time, by using attributes. The incidents can be specified with the following attributes: OBJECTID—The system-managed ID field. SHAPE—The geometry field indicating the geographic location of the incident. Name—The name of the incident. The name is used in the driving directions. If the name is not specified, a unique name prefixed with Location is automatically generated in the output routes and directions. ID—A unique identifier for the incident. The identifier is included in the output routes (as the IncidentID field) and can help join additional information from the output routes, such as the total travel time or total distance, to attributes from your incidents or vice versa. If the ID isn't specified, the service automatically generates a unique identifier for each incident. AdditionalTime—The amount of time spent at the incident, which is added to the total time of the route. The units for this attribute value are specified by the Measurement Units parameter. The attribute value is included in the analysis only when the measurement units are time based. The default value is 0. If you are finding the closest fire stations from fire incidents to estimate response times, the AdditionalTime attribute can store the amount of time it takes firefighters to hook up their equipment at the location of the incident before they can begin fighting the fire. AdditionalDistance—The extra distance traveled at the incident, which is added to the total distance of the route. The units for this attribute value are specified by the Measurement Units parameter. The attribute value is included in the analysis only when the measurement units are distance based. The default value is 0. Generally, the location of an incident, such as a home, isn't exactly on the streets; it is set back somewhat from the road. This attribute value can be used to model the distance between the actual incident location and its location on the street, if it is important to include that distance in the total travel distance. CurbApproach—Specifies the direction a vehicle may arrive at and depart from the incident. The field value is specified as one of the following integers (use the numeric code, not the name in parentheses):
The CurbApproach property is designed to work with both kinds of national driving standards: right-hand traffic (United States) and left-hand traffic (United Kingdom). First, consider an incident on the left side of a vehicle. It is always on the left side regardless of whether the vehicle travels on the left or right half of the road. What may change with national driving standards is your decision to approach an incident from one of two directions, that is, so it ends up on the right or left side of the vehicle. For example, if you want to arrive at an incident and not have a lane of traffic between the vehicle and the incident, you would choose Right side of vehicle (1) in the United States but Left side of vehicle (2) in the United Kingdom. | Feature Set |
Facilities | This tool finds the nearest facilities to incidents, and this parameter specifies those facilities. A minimum of one facility is necessary to solve an analysis. When specifying the facilities, you can set properties for each one, such as its name or service time, by using attributes. The facilities can be specified with the following attributes: Name—The name of the facility. The name is used in the driving directions. If the name is not specified, a unique name prefixed with Location is automatically generated in the output routes and directions. ID—A unique identifier for the facility. The identifier is included in the output routes (as the FacilityID field) and the output closest facilities as FacilityID fields. The FacilityID field can be used to join additional information from the output routes, such as the total travel time or total distance, to attributes from your facilities. If the ID isn't specified, the service automatically generates a unique identifier for each facility. AdditionalTime—The amount of time spent at the facility, which is added to the total time of the route. The units for this attribute value are specified by the Measurement Units parameter. The attribute value is included in the analysis only when the measurement units are time based. The default value is 0. If you are finding the closest fire stations to fire incidents, AdditionalTime can store the time it tends to take a crew to don the appropriate protective equipment and exit the fire station. AdditionalDistance—The extra distance traveled at the facility, which is added to the total distance of the route. The units for this attribute value are specified by the Measurement Units parameter. The attribute value is included in the analysis only when the measurement units are distance based. The default value is 0. Generally, the location of a facility, such as a fire station, isn't exactly on a street; it is set back somewhat from the road. AdditionalDistance can model the distance between the actual facility location and its location on the street, if it is important to include that distance in the total travel distance. CurbApproach—Specifies the direction a vehicle may arrive at and depart from the facility. The field value is specified as one of the following integers (use the numeric code, not the name in parentheses):
The CurbApproach property was designed to work with both kinds of national driving standards: right-hand traffic (United States) and left-hand traffic (United Kingdom). First, consider a facility on the left side of a vehicle. It is always on the left side regardless of whether the vehicle travels on the left or right half of the road. What may change with national driving standards is your decision to approach a facility from one of two directions, that is, so it ends up on the right or left side of the vehicle. For example, if you want to arrive at a facility and not have a lane of traffic between the vehicle and the facility, you would choose Right side of vehicle (1) in the United States but Left side of vehicle (2) in the United Kingdom. | Feature Set |
Measurement_Units | Specify the units that should be used to measure and report the total travel time or travel distance for the output routes. The tool finds the closest facility by measuring the travel time or the travel distance along streets. The units you choose for this parameter determine whether the tool will measure driving distance or driving time to find what is closest. Choose a time unit to measure driving time. To measure driving distance, choose a distance unit. Your choice also determines in which units the tool will report total driving time or distance in the results. The choices include the following:
The tool chooses whether to use the network cost attribute specified in the Time Attribute or Distance Attribute parameter depending on whether the chosen measurement units are time or distance based. The tool performs the necessary unit conversion when the Measurement Units value differs from the units of the corresponding time or distance cost attribute. | String |
Network_Dataset | The network dataset on which the analysis will be performed. Network datasets most often represent street networks but may represent other kinds of transportation networks as well. The network dataset needs at least one time-based and one distance-based cost attribute. | Network Dataset Layer |
Output_Geodatabase | The output workspace. This workspace must already exist. The default output workspace is in_memory. | Workspace |
Output_Routes_Name | The name of the output feature class containing routes or the lines that connect incidents to their closest facilities. This feature class also contains, as an attribute, the total cost of travel between the incidents and their nearest facilities. The help topic Output from Find Closest Facilities describes the schema of this output feature class. | String |
Output_Directions_Name | The name of the output feature class containing directions. The help topic Output from Find Closest Facilities describes the schema of this output feature class. | String |
Output_Closest_Facilities_Name | The name of the output feature class containing the closest facilities. The help topic Output from Find Closest Facilities describes the schema of this output feature class. | String |
Number_of_Facilities_to_Find (Optional) | Specify the number of closest facilities to find per incident. This is useful in situations, such as a fire, where multiple fire engines may be required from different fire stations. You can specify, for example, to find the three nearest fire stations to a fire. If you are setting up a service from this tool, and you want to limit resource usage such as processing time on your server, use the Maximum Facilities to Find parameter to limit the maximum number of facilities a user can enter in Number of Facilities to Find. | Long |
Default_Cutoff (Optional) | Specify the travel time or travel distance value at which to stop searching for facilities for a given incident. For instance, while finding the closest hospitals from the site of an accident, a cutoff value of 15 minutes would mean that the tool would search for the closest hospital within 15 minutes from the incident. If the closest hospital is 17 minutes away, no routes will be returned in the output routes. A cutoff value is especially useful when searching for multiple facilities. The units for this parameter is specified by the Measurement Units parameter. | Double |
Travel_Direction (Optional) | Specify whether you want to search for the closest facility as measured from the incident to the facility or from the facility to the incident.
Using one of the parameter values can find different facilities as the travel time along some streets may vary based on the travel direction and one-way restrictions. 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. If you are setting a value for Time of Day, traffic may also cause the Facility to Incident and Incident to Facility options to return different results. | String |
Time_of_Day (Optional) |
Specifies the time and date at which the routes should begin or end. The value is used as the start time or end time for the route depending on the value for the Time of Day Usageparameter. If you specify the current date and time as the value for this parameter, the tool will use live traffic conditions to find the closest facilities and the total travel time will be based on traffic conditions. If your network dataset contains live or historical traffic data, specifying a time of day results in more accurate estimation of travel time between the incident and facility because the travel times account for the traffic conditions that are applicable for that date and time. The Time Zone for Time of Day parameter specifies whether this time and date refer to UTC or the time zone in which the facility or incident is located. Irrespective of the Time Zone for Time of Day setting, if your facilities and incidents are in multiple time zones, the following rules are enforced by the tool:
| Date |
Time_of_Day_Usage (Optional) | Indicates whether the Time of Day parameter value represents the arrival or departure time for the routes.
| String |
Time_Zone_for_Time_of_Day (Optional) | Specifies the time zone of the Time of Day parameter.
Irrespective of the Time Zone for Time of Day setting, if your facilities and incidents are in multiple time zones, the following rules are enforced by the tool:
| String |
UTurn_Policy (Optional) | The U-Turn policy at junctions. Allowing U-turns implies the solver can turn around at a junction and double back on the same street. Given that junctions represent street intersections and dead ends, different vehicles may be able to turn around at some junctions but not at others—it depends on whether the junction represents an intersection or dead end. To accommodate, the U-turn policy parameter is implicitly specified by how many edges connect to the junction, which is known as junction valency. The acceptable values for this parameter are listed below; each is followed by a description of its meaning in terms of junction valency.
The value of this parameter is overridden when Travel Mode (Travel_Mode in Python) is set to any value other than custom. | String |
Point_Barriers (Optional) | Specifies point barriers, which are split into two types: restriction and added cost point barriers. They temporarily restrict traversal across or add impedance to points on the network. The point barriers are defined by a feature set, and the attribute values you specify for the point features determine whether they are restriction or added cost barriers. The fields in the attribute table are listed and described below. ObjectID: The system-managed ID field. Shape: The geometry field indicating the geographic location of the network analysis object. Name: The name of the barrier. BarrierType: Specifies whether the barrier restricts travel completely or adds cost when traveling through it. There are two options:
Use the value 0 for Restriction and 2 for Added Cost. Additional_Time: Indicates how much travel time is added when the barrier is traversed. This field is applicable only for added-cost barriers and only if the measurement units are time based. This field value must be greater than or equal to zero, and its units are the same as those specified in the measurement units parameter. Additional_Distance: Indicates how much distance is added when the barrier is traversed. This field is applicable only for added-cost barriers and only if the measurement units are distance based. The field value must be greater than or equal to zero, and its units are the same as those specified in the measurement units parameter. | Feature Set |
Line_Barriers (Optional) |
Specifies line barriers, which temporarily restrict traversal across them. The line barriers are defined by a feature set. The fields in the attribute table are listed and described below. ObjectID: The system-managed ID field. Shape: The geometry field indicating the geographic location of the network analysis object. Name: The name of the barrier. | Feature Set |
Polygon_Barriers (Optional) | Specifies polygon barriers, which are split into two types: restriction and scaled cost polygon barriers. They temporarily restrict traversal or scale impedance on the parts of the network they cover. The polygon barriers are defined by a feature set, and the attribute values you specify for the polygon features determine whether they are restriction or scaled cost barriers. The fields in the attribute table are listed and described below. ObjectID: The system-managed ID field. Shape: The geometry field indicating the geographic location of the network analysis object. Name: The name of the barrier. BarrierType: Specifies whether the barrier restricts travel completely or scales the cost of traveling through it. There are two options:
Use the value 0 for Restriction and 1 for Scaled Cost. ScaledTimeFactor: This is the factor by which the travel time of the streets intersected by the barrier is multiplied. This field is applicable only for scaled-cost barriers and only if the measurement units are time based. The field value must be greater than zero. ScaledDistanceFactor: This is the factor by which the distance of the streets intersected by the barrier is multiplied. This attribute is applicable only for scaled-cost barriers and only if the measurement units are distance based. The attribute value must be greater than zero. | Feature Set |
Time_Attribute (Optional) | Defines the network cost attribute to use when the measurement units value is a time unit. The tool performs the necessary time-unit conversion when the measurement units value differs from the units of the cost attribute defined here. In other words, the time units of the default cutoff and the network cost attribute don't need to be the same. The value of this parameter is overridden when Travel Mode (Travel_Mode in Python) is set to any value other than Custom. | String |
Time_Attribute_Units (Optional) | The units of the time attribute. You can explicitly set the time attribute units, but it is recommended to pass nothing or "#" and let the solver determine the units. The value of this parameter is overridden when Travel_Mode is set to any value other than CUSTOM. | String |
Distance_Attribute (Optional) | Defines the network cost attribute to use when the measurement units value is a distance unit. The tool performs the necessary distance-unit conversion when the measurement units value differs from the units of the cost attribute defined here. In other words, the measurement units and the distance units of the network cost attribute don't need to be the same. The value of this parameter is overridden when Travel Mode (Travel_Mode in Python) is set to any value other than Custom. | String |
Distance_Attribute_Units (Optional) | The units of the distance attribute. You can explicitly set the distance attribute units, but it is recommended to pass nothing or "#" and let the solver determine the units. The value of this parameter is overridden when Travel_Mode is set to any value other than CUSTOM. | String |
Use_Hierarchy_in_Analysis (Optional) | Specify whether hierarchy should be used when finding the shortest routes between points.
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. You can use the Force_Hierarchy_Beyond_Distance parameter to force the solve to use hierarchy even if Use_Hierarchy_in_Analysis is set to False. This parameter is ignored unless Travel_Mode is set to CUSTOM. When modeling a custom walking mode, it is recommended to turn off hierarchy since the hierarchy is designed for motorized vehicles. | Boolean |
Restrictions [restriction,...] (Optional) | Indicates which network restriction attributes are respected during solve time. The value of this parameter is overridden when Travel Mode (Travel_Mode in Python) is set to any value other than custom. | String |
Attribute_Parameter_Values (Optional) | Specifies the parameter values for network attributes that have parameters. The record set has two columns that work together to uniquely identify parameters and another column that specifies the parameter value. The value of this parameter is overridden when Travel Mode (Travel_Mode in Python) is set to any value other than custom. The attribute parameter values record set has associated attributes. The fields in the attribute table are listed below and described. ObjectID: The system-managed ID field. AttributeName: The name of the network attribute whose attribute parameter is set by the table row. ParameterName: The name of the attribute parameter whose value is set by the table row. (Object type parameters cannot be updated using this tool.) ParameterValue: The value you want for the attribute parameter. If a value is not specified, the attribute parameter is set to null. | Record Set |
Accumulate_Attributes [attribute,...] (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 Time Attribute (Time_Attribute in Python) or Distance Attribute (Distance_Attribute in Python) parameter to calculate the shortest paths. For each cost attribute that is accumulated, a Total_[attribute] field is added to the routes that are output by the solver. | String |
Maximum_Snap_Tolerance (Optional) | The maximum snap tolerance is the furthest distance that Network Analyst searches when locating or relocating a point onto the network. The search looks for suitable edges or junctions and snaps the point to the nearest one. If a suitable location isn't found within the maximum snap tolerance, the object is marked as unlocated. | Linear Unit |
Feature_Locator_WHERE_Clause (Optional) | An SQL expression used to select a subset of source features that limits on which network elements facilities can be located. The syntax for this parameter consists of two parts: the first is the source feature class name (followed by a space) and the second is the SQL expression. To write an SQL expression for two or more source feature classes, separate them with a semicolon. To ensure facilities are not located on limited-access highways, for example, write an SQL expression like the following to exclude those source features: "Streets" "FUNC_CLASS not in('1', '2')". Note that barriers ignore the feature locator WHERE clause when loading. | String |
Route_Shape (Optional) | Specify the type of route features that are output by the tool. The parameter can be specified using one of the following values:
When the Route Shape parameter is set to True Shape, the generalization of the route shape can be further controlled using the appropriate values for the Route Line Simplification Toleranceparameter. No matter which value you choose for the Route Shapeparameter, the best route is always determined by minimizing the travel time or the travel distance, never using the straight-line distance between incidents and facilities. This means that only the route shapes are different, not the underlying streets that are searched when finding the route. | String |
Route_Line_Simplification_Tolerance (Optional) | Specify by how much you want to simplify the route geometry. The tool ignores this parameter if the Route_Shape parameter isn't set to TRUE_LINES_WITH_MEASURES or TRUE_LINES_WITHOUT_MEASURES. Simplification maintains critical points on a route, such as turns at intersections, to define the essential shape of the route and removes other points. The simplification distance you specify is the maximum allowable offset that the simplified line can deviate from the original line. Simplifying a line reduces the number of vertices that are part of the route geometry. This improves the tool execution time. The value of this parameter is overridden when Travel Mode (Travel_Mode in Python) is set to any value other than custom. | Linear Unit |
Populate_Directions (Optional) | Specify whether the tool should generate driving directions for each route.
| Boolean |
Directions_Language (Optional) | Specify the language that should be used when generating driving directions. This parameter is used only when the Populate Directions parameter is checked, or set to True. The directions languages that are available depend on what ArcGIS language packs you have installed on your computer. The values are entered in two- or five-character language codes, for example, en for English or zh-CN for simplified Chinese. If an unsupported language code is specified, the tool returns the directions using the default language, English. | String |
Directions_Distance_Units (Optional) | Specify the units for displaying travel distance in the driving directions. This parameter is used only when the Populate Directions parameter is checked, or set to True.
| String |
Directions_Style_Name (Optional) | Specify the name of the formatting style for the directions. This parameter is used only when the Populate Directions parameter is checked, or set to True. The parameter can be specified using the following values:
| String |
Maximum_Features_Affected_by_Point_Barriers (Optional) | Limits how many features can be affected by point barriers. This parameter helps you govern the amount of processing that occurs when solving. For example, you could assign a low value to this parameter for a free version of the service you are creating and use a higher value for a paid-subscription version of the service. A null value indicates there is no limit. | Long |
Maximum_Features_Affected_by_Line_Barriers (Optional) |
Limits how many features can be affected by line barriers. This parameter helps you govern the amount of processing that occurs when solving. For example, you could assign a low value to this parameter for a free version of the service you are creating and use a higher value for a paid-subscription version of the service. A null value indicates there is no limit. | Long |
Maximum_Features_Affected_by_Polygon_Barriers (Optional) |
Limits how many features can be affected by polygon barriers. This parameter helps you govern the amount of processing that occurs when solving. For example, you could assign a low value to this parameter for a free version of the service you are creating and use a higher value for a paid-subscription version of the service. A null value indicates there is no limit. | Long |
Maximum_Facilities (Optional) | Limits how many facilities can be added to the closest facility analysis. This parameter helps you govern the amount of processing that occurs when solving. For example, you could assign a low value to this parameter for a free version of the service you are creating and use a higher value for a paid-subscription version of the service. A null value indicates there is no limit. | Long |
Maximum_Facilities_to_Find (Optional) | Limits how many facilities the user can ask the service to find. This parameter helps you govern the amount of processing that occurs when solving. For example, you could assign a low value to this parameter for a free version of the service you are creating and use a higher value for a paid-subscription version of the service. A null value indicates there is no limit. | Long |
Maximum_Incidents (Optional) | Limits how many incidents can be added to the closest facility analysis. This parameter helps you govern the amount of processing that occurs when solving. For example, you could assign a low value to this parameter for a free version of the service you are creating and use a higher value for a paid-subscription version of the service. A null value indicates there is no limit. | Long |
Force_Hierarchy_Beyond_Distance (Optional) | Specifies the distance after which the solver will force hierarchy, even if hierarchy is not enabled, when finding closest facilities. The units of this parameter are the same as those shown in the Distance Attribute Units parameter. Finding closest facilities that are far away while using the network's hierarchy tends to incur much less processing than finding the same closest facilities without using the hierarchy. This parameter helps you govern the amount of processing that occurs when solving. A null value indicates that the hierarchy will never be enforced and the value of the Use Hierarchy in Analysis parameter will always be honored. If the input network dataset does not support hierarchy, specifying a value for this parameter will result in an error. A null value should be used in this case. | Double |
Save_Output_Network_Analysis_Layer (Optional) |
In either case, feature classes with routes and directions are returned. However, a server administrator may want to choose to output a network analysis layer as well so the setup and results of the tool can be debugged using the Network Analyst controls in the ArcGIS Desktop environment. This can make the debugging process much easier. In ArcGIS Desktop, the default output location for the network analysis layer is in the scratch folder. You can determine the location of the scratch folder by evaluating the value of arcpy.env.scratchFolder geoprocessing environment. The output network analysis layer is stored as an LYR file whose name begins with _ags_gpna and is followed by an alphanumeric GUID. | Boolean |
Travel_Mode (Optional) | Choose the mode of transportation for the analysis. CUSTOM is always a choice. For other travel mode names to appear, they must be present in the network dataset specified in the Network_Dataset parameter. (The arcpy.na.GetTravelModes function provides a dictionary of the travel mode objects configured on a network dataset, and the name property returns the name of a travel mode object.) A travel mode is defined on a network dataset and provides override values for parameters that, together, model car, truck, pedestrian, or other modes of travel. By choosing a travel mode here, you don't need to provide values for the following parameters, which are overridden by values specified in the network dataset:
| String |
Overrides (Optional) | Specify additional settings that can influence the behavior of the solver when finding solutions for the network analysis problems. The value for this parameter needs to be specified in JavaScript Object Notation (JSON). For example, a valid value is of the following form {"overrideSetting1" : "value1", "overrideSetting2" : "value2"}. The override setting name is always enclosed in double quotation marks. The values can be either a number, Boolean, or a string. The default value for this parameter is no value, which indicates not to override any solver settings. Overrides are advanced settings that should be used only after careful analysis of the results obtained before and after applying the settings. A list of supported override settings for each solver and their acceptable values can be obtained by contacting Esri Technical Support. | String |
Save_Route_Data (Optional) | Choose whether the output includes zip file that contains a file geodatabase holding the inputs and outputs of the analysis in a format that can be used to share route layers with online or portal. In ArcGIS Desktop, the default output location for this output file is in the scratch folder. You can determine the location of the scratch folder by evaluating the value of arcpy.env.scratchFolder geoprocessing environment.
| Boolean |
Derived Output
Name | Explanation | Data Type |
Output_Routes | Resulting route or routes between the facilities and the incidents. | Feature Set |
Output_Directions | Turn-by-turn driving directions for each resulting route between the facilities and the incidents. | Feature Set |
Solve_Succeeded | Indicates whether solving the closest facility analysis succeeded. | Boolean |
Output_Closest_Facilities | The facilities that were closest to the incidents. | Feature Set |
Output_Network_Analysis_layer | Network analysis layer with properties as configured in the tool parameters that can be used for further analysis or debugging in the map. | File |
Output_Route_Data | A zip file containing all the information for a particular route. | File |
Code sample
FindClosestFacilities example 1 (Python window)
Execute the FindClosestFacilities tool using the required parameters.
import arcpy
incidents = arcpy.FeatureSet()
incidents.load("Stores")
facilities = arcpy.FeatureSet()
facilities.load("Warehouses")
arcpy.na.FindClosestFacilities(incidents, facilities, "Minutes",
"Streets_ND", "in_memory", "Routes",
"Directions", "CLosestFacilities",
Number_of_Facilities_to_Find=1)
FindClosestFacilities example 2 (stand-alone script)
The following stand-alone Python script demonstrates how FindClosestFacilities can determine the nearest stores to a warehouse. You can modify the script to use other inputs to find the closest ambulance to an accident, work crew to a downed power line, and so on.
# Name: FindClosestFacilities_Workflow.py
# Description: For each store, find the closest warehouse. The output will show
# the routes between stores and warehouses, driving directions,
# and the subset of warehouses that were closest to stores.
# Requirements: Network Analyst Extension
#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 = r'C:\arcgis\ArcTutor\Network Analyst\Tutorial\Paris.gdb'
env.overwriteOutput = True
#Set local variables
inNetworkDataset = r'Transportation\ParisMultimodal_ND'
inIncidents = r'Analysis\Stores'
inFacilities = r'Analysis\Warehouses'
outGeodatabase = r'C:\arcgis\ArcTutor\Network Analyst\Tutorial\Output.gdb'
outRoutes = "Routes"
outDirections = "Directions"
outClosestFacilities = "ClosestFacilities"
measurement_units = "Minutes"
# Run FindClosestFacilities. Choose to find only the closest facility.
arcpy.na.FindClosestFacilities(inIncidents, inFacilities, measurement_units,
inNetworkDataset, outGeodatabase, outRoutes,
outDirections, outClosestFacilities,
Number_of_Facilities_to_Find=1)
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
Licensing information
- Basic: Requires Network Analyst
- Standard: Requires Network Analyst
- Advanced: Requires Network Analyst