Use routing services from a standalone ArcGIS Server site

You can perform network analysis with the arcpy.nax module using routing services from a stand-alone ArcGIS Server site. The solver classes (ClosestFacility, LocationAllocation, OriginDestinationCostMatrix, Route, ServiceArea, VehicleRoutingProblem) and the GetTravelModes and GetWebToolInfo functions are supported.

Learn more about stand-alone ArcGIS Server sites

Learn how to publish routing services to your ArcGIS Server site

Specify a stand-alone ArcGIS Server site in code

When writing your code, instead of a path to a network dataset or a URL to an ArcGIS Enterprise portal, use a Python dictionary to specify the stand-alone ArcGIS Server site URLs and authentication information.

The routing service info dictionary includes the following keys:

  • url—The REST URL to the routing service. The URL should include the name of the service but should not include the name of the tool within the service. This key is optional for the GetTravelModes and GetWebToolInfo functions but is required for instantiating solver classes.
  • utilityUrl—The REST URL to the utilities service containing tools that provide auxiliary information about the routing service. The URL should not include the tool name. This key is required.
  • authenticationInfo—A Python dictionary containing the credentials to use when authenticating the service connection. More information about how to specify this dictionary is given below. This key is not needed for unsecured services.

注意:

The routing service URLs in the examples below assume that the stand-alone ArcGIS Server site uses ArcGIS Web Adaptor.

Learn how to construct appropriate URLs for other configurations

Unsecured service

For an unsecured service, the authenticationInfo key is not required.

The following is an example of a routing service info dictionary for an unsecured service.

{
    "url": "https://webadaptorhost.domain.com/webadaptorname/rest/services/Routing/NetworkAnalysis/GPServer",
    "utilityUrl": "https://webadaptorhost.domain.com/webadaptorname/rest/services/Routing/NetworkAnalysisUtilities/GPServer"
}

Secured service with built-in authentication

For a secured service with built-in authentication, the authenticationInfo key is required, and its value can be specified in multiple ways.

注意:

A connection file is the most secure way to store credentials. Other authentication methods are less secure.

Authentication using a username and password

To authenticate using a username and password, the authenticationInfo dictionary requires the username and password keys. The values are the plain text username and password to use to connect to the service.

The following is an example of a routing service info dictionary for a service with built-in authentication using a username and password.

{
    "url": "https://webadaptorhost.domain.com/webadaptorname/rest/services/Routing/NetworkAnalysis/GPServer",
    "utilityUrl": "https://webadaptorhost.domain.com/webadaptorname/rest/services/Routing/NetworkAnalysisUtilities/GPServer",
    "authenticationInfo": {
        "username": "my_username",
        "password": "my_password"
    }
}

Authentication using a connection file

To authenticate using a connection file (.ags), the authenticationInfo dictionary requires the connectionFile key.

Learn how to create a connection file

The following is an example of a routing service info dictionary for a service with built-in authentication using a connection file.

{
    "url": "https://webadaptorhost.domain.com/webadaptorname/rest/services/Routing/NetworkAnalysis/GPServer",
    "utilityUrl": "https://webadaptorhost.domain.com/webadaptorname/rest/services/Routing/NetworkAnalysisUtilities/GPServer",
    "authenticationInfo": {
        "connectionFile": "C:\\data\\my_connection_file.ags"
    }
}