Share As Route Layers (Network Analyst)

Summary

Shares the results of network analyses as route layer items in a portal. A route layer includes all the information for a route such as the stops assigned to the route or the orders serviced by a route, as well as the travel directions.

A route layer item can be used by various applications, such as ArcGIS Navigator to provide route guidance for mobile workers, the Directions pane in Map Viewer Classic to further customize the route contained in the route layer, and ArcGIS AllSource to create a route analysis layer from a route layer.

Usage

  • The tool creates and shares the route layer items in the portal that is designated as the active portal. The active portal must be ArcGIS Online or ArcGIS Enterprise 10.5.1 or later.

  • The user that is signed in to the active portal must have the necessary privileges to run spatial analysis and create content.

  • If a route layer item with the same name exists in the specified folder, a new item with the same name will be created. One way to avoid creating duplicate items is to use a unique Route Name Prefix value when creating route layers using this tool.

  • When using this tool in a Python script, the active portal where ArcGIS AllSource was last accessed is the portal that will be used to create the route layers.

  • The maximum number of route layers that can be created is 1,000. If the input route data contains more than 1,000 routes, the task will fail with an error message.

Parameters

LabelExplanationData Type
Input Network Analysis Layer or Route Data

The network analysis layer from which the route layer items will be created. The network analysis layer should already be solved.

Route, Closest facility, Vehicle routing problem, and Last mile delivery network analysis layers are supported as valid inputs to this parameter.

The input can also be a .zip file containing route data created by the saveRouteData() method of the arcpy.nax solver result objects or the service parameter in the REST API that return a zipped geodatabase of route data with the correct schema.

File; Network Analyst Layer
Summary
(Optional)

The summary that will be used by the route layer items. The summary is displayed as part of the item information for the route layer item. If no value is provided, default summary text—Route and directions for <route name>—is used in which <route name> is replaced with the name of the route represented by the route layer.

String
Tags
(Optional)

The tags that will be used to describe and identify the route layer items. Individual tags are separated with commas. The route name is always included as a tag even when no other value is provided.

String
Route Name Prefix
(Optional)

A qualifier that will be added to the title of every route layer item. For example, a route name prefix of Monday morning deliveries can be used to group all route layer items created from a route analysis performed by deliveries that will be run on Monday morning. If no value is specified, the title of the route layer item will be created using only the route name.

String
Portal Folder Name
(Optional)

The folder in your personal online workspace where the route layer items will be created. If a folder with the provided name does not exist, a folder will be created. If a folder with the provided name exists, the items will be created in the existing folder. If no value is provided, the route layer items will be created in the root folder of your online workspace.

String
Share with
(Optional)

Specifies who can access the route layer items.

  • Everyone The route layer items will be public and can be accessed by anyone with the URL to the items.
  • Not shared The route layer items will only be shared with the owner of the item (the user connected to the portal when the tool is run). As a result, only the item owner can access the route layers. This is the default.
  • These groups The route layer items will be shared with groups the connected user belongs to and its members. The groups are specified using the groups parameter.
  • Organization The route layer items will be shared with all authenticated users in your organization.
String
Groups
(Optional)

The list of groups with which the route layer items will be shared. This parameter is applicable only when the Share with parameter is set to These groups.

String

Derived Output

LabelExplanationData Type
Route Layer Items

Route layer items shared in a portal.

String

arcpy.management.ShareAsRouteLayers(in_network_analysis_layer, {summary}, {tags}, {route_name_prefix}, {portal_folder_name}, {share_with}, {groups})
NameExplanationData Type
in_network_analysis_layer

The network analysis layer from which the route layer items will be created. The network analysis layer should already be solved.

Route, Closest facility, Vehicle routing problem, and Last mile delivery network analysis layers are supported as valid inputs to this parameter.

The input can also be a .zip file containing route data created by the saveRouteData() method of the arcpy.nax solver result objects or the service parameter in the REST API that return a zipped geodatabase of route data with the correct schema.

File; Network Analyst Layer
summary
(Optional)

The summary that will be used by the route layer items. The summary is displayed as part of the item information for the route layer item. If no value is provided, default summary text—Route and directions for <route name>—is used in which <route name> is replaced with the name of the route represented by the route layer.

String
tags
(Optional)

The tags that will be used to describe and identify the route layer items. Individual tags are separated with commas. The route name is always included as a tag even when no other value is provided.

String
route_name_prefix
(Optional)

A qualifier that will be added to the title of every route layer item. For example, a route name prefix of Monday morning deliveries can be used to group all route layer items created from a route analysis performed by deliveries that will be run on Monday morning. If no value is specified, the title of the route layer item will be created using only the route name.

String
portal_folder_name
(Optional)

The folder in your personal online workspace where the route layer items will be created. If a folder with the provided name does not exist, a folder will be created. If a folder with the provided name exists, the items will be created in the existing folder. If no value is provided, the route layer items will be created in the root folder of your online workspace.

String
share_with
(Optional)

Specifies who can access the route layer items.

  • EVERYBODY The route layer items will be public and can be accessed by anyone with the URL to the items.
  • MYCONTENT The route layer items will only be shared with the owner of the item (the user connected to the portal when the tool is run). As a result, only the item owner can access the route layers. This is the default.
  • MYGROUPS The route layer items will be shared with groups the connected user belongs to and its members. The groups are specified using the groups parameter.
  • MYORGANIZATION The route layer items will be shared with all authenticated users in your organization.
String
groups
[groups,...]
(Optional)

The list of groups with which the route layer items will be shared. This parameter is applicable only when the share_with parameter is set to MYGROUPS.

String

Derived Output

NameExplanationData Type
route_layer_items

Route layer items shared in a portal.

String

Code sample

ShareAsRouteLayers example (Python window)

The following example demonstrates how to share a solved route analysis as a route layer to your active portal using only the required parameters.

arcpy.na.ShareAsRouteLayers('Route')
ShareAsRouteLayers example 2 (stand-alone script)

The following example demonstrates how to share a solved route analysis as a route layer specifying a summary and tags for the route layer item. The route layer item name starts with the prefix Wednesday Route for Food Inspection. The route layer is created in a folder named RouteLayers in your active portal and shared with a group named Drivers in your portal.

arcpy.na.ShareAsRouteLayers('Route', 'Share route solve result as route layers', 
                            'Food inspection', 'Wednesday Route for Food Inspection', 
                            'RouteLayers', 'MYGROUPS', 'Drivers')
ShareAsRouteLayers example 3 (stand-alone script)

The following stand-alone Python script demonstrates how the ShareAsRouteLayers function can be used to share a solved Closest Facilities network analysis layer to the active portal.

# Name: ShareAsRouteLayers_Workflow.py
# Description: Find the closest warehouse from the store locations and share the
#              results as route layers.
# 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.")

    # Check if logged into active Portal. Fail if not logged into actiave portal.
    if arcpy.GetSigininToken() is None:
        raise arcpy.ExecuteError("Please sign in to your active portal in ArcGIS Pro.")
    
    # 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")

    # 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)

    # Share the routes from the closest facility analysis as route layers
    arcpy.na.ShareAsRouteLayers(layer_object, "Share closest facility solve result as route layers")

    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))