Available with Network Analyst license.
Network analysis can be performed on a transportation network over the web by hosting network analysis services on ArcGIS Server. This includes finding the closest facility, the best route for a vehicle, the best routes for a fleet of vehicles; locating facilities using location-allocation; calculating an OD cost matrix; and generating service areas. This tutorial walks you through the process of creating a map document capable of being used for network analysis and publishing it as a network analysis service. It then refers you to help on how to consume the network analysis service in ArcMap and a web application. To learn more about the different types of network analysis and their capabilities, see Types of network analyses in the ArcGIS Help.
Before beginning this tutorial
If you've just installed ArcGIS Server, you need to complete some preparatory steps before you can connect to the server and publish services:
- For details on how to configure your ArcGIS Server site, see the Getting started after install section of this help system.
- To learn how to make the data referenced by your GIS resource available to the server, see the topic Making your data accessible to ArcGIS Server.
Tutorial data
The data for this tutorial is installed with ArcGIS Server and is located at <ArcGIS for Server installation directory>\help\samples\data\network_analyst.
Optionally, you can try to work through the steps using your own data instead.
Creating the map document
A network analysis service requires a map service that contains one or more network analysis layers. This means the map document published to the server must contain one or more layers that are network analysis layers created with tools from the Network Analyst toolbar. Network analysis services support route, closest facility, and service area analysis layers.
Follow these steps to create a single map document capable of performing all three of these types of network analysis:
- Start ArcMap and open a new blank map document.
- Click Customize > Extensions and check Network Analyst to enable the Network Analyst extension.
- Click Customize > Toolbars > Network Analyst to make the Network Analyst toolbar visible.
- Add a network dataset, which is required to be in the map to create a network analysis layer, by clicking Add Data on the standard toolbar. Browse to the Streets_ND network dataset located in the SanFrancisco database. When prompted to add all feature classes that participate in Streets_ND to the map, click No.
- Add a route network analysis layer to your map by clicking the Network Analyst drop-down menu on the Network Analyst toolbar and choosing New Route.
When a network analysis layer is created in ArcMap, it is automatically bound to the active network dataset. The San Francisco network was active when you created the route analysis layer, so these two layers are bound together. Also, the network analysis layer references the network dataset it is bound to by file path, so the network dataset layer is no longer needed in ArcMap.
- Right-click Streets_ND or the name of your network dataset layer and click Remove. Although the map is blank, the route analysis layer is present and can be published as a service. When you eventually add the published network analysis service to a map, it won't display any features initially, that is, until it generates results. To provide additional context when you consume a network analysis service, you can also consume a cached map service, such as one provided by ArcGIS Online.
- Click File > Save As to save the map document.
Publishing the network analysis service
Once you have a map document with a network analysis layer, you're ready to publish it as a network analysis service. You'll publish the map document as a service and enable the network analysis capability, which creates a network analysis service of the same name.
To configure and publish your map document to ArcGIS Server using ArcMap, follow these steps.
- Remaining in ArcMap, choose File > Share As > Service from the main menu.
- In the Share as Service window, choose Publish a service. Click Next.
- In the Publish a Service dialog box, click Connect to ArcGIS Server to create a new connection to the server.
- In the Add ArcGIS Server window, choose Publish GIS Services. Click Next.
- For the Server URL, type the URL of the ArcGIS Server site you want to connect to. For example, http://gisserver.domain.com:6080/arcgis.
- From the Server Type drop-down list, choose ArcGIS Server.
- During the publishing process, a service definition file is created and temporarily stored locally on disk. When the publishing process completes, the service definition uploads to the server and the local file is deleted. For the purposes of this tutorial, accept the default staging folder and continue.
- If your server administrator has enabled security for your site, enter your User Name and Password. Click Finish.
- Optionally, in the Publish a Service window, enter a new name for the service. The name cannot be more than 120 characters long and may contain only alphanumeric characters and underscores. Click Next.
- By default, services are published to the root folder (root) of ArcGIS Server. Services can be organized into subfolders under the root folder. Choose the folder where you want to publish the service or create a new folder to contain the service. Click Continue.
- The Service Editor displays. You'll use the Service Editor to choose what users can do with your network analysis service and take fine-grained control of how the server exposes your service. Click the Capabilities tab.
- By default, mapping and KML are enabled. Check Network Analysis.
- In the left pane of the Service Editor, click the Network Analysis tab and review the operations and properties enabled for your network analysis service. For the purposes of this tutorial, you can accept the defaults and continue. However, if you want to learn more, see Network analysis services. For information on how to best configure your network analysis service for deployment, see Tuning and configuring services.
- Click Analyze. This examines your map document to see if it can be published to the server.
Tip:
To give yourself more viewing area when configuring your network analysis service, click the Collapse button at the top of the Service Editor.
- Fix any Errors in the Prepare window; this must be done before you can publish. Optionally, you can fix warnings and informational messages to further improve the performance and appearance of your network analysis service. For more information about resolving these issues, see Analyzing your GIS resource.
Note:
You can register folders and geodatabases with your ArcGIS Server site, thus ensuring that the server can recognize and use your data. If you proceed with the following steps, any data referenced by your map document originating from an unregister folder or geodatabase is copied to the server at the time that you publish. This is a precautionary measure to ensure that the server can access all the data used by the service. For full instructions on registering a folder or geodatabase with your ArcGIS Server site, see Registering your data with ArcGIS Server using ArcGIS for Desktop.
- Once you've fixed the errors in your map document, click Publish.
Your map document publishes to ArcGIS Server, which creates a map service and an associated network analysis service with the same name.
Consuming the network analysis service
Clients of ArcGIS Server, for example, ArcGIS for Desktop and web browsers, have the capability to consume network analysis services. In ArcMap, the Find Route button provides you with out-of-the-box functionality to utilize routing capabilities provided by your network analysis service. In web browsers, network analysis services are consumed programmatically through web applications built with ArcGIS.com, Portal for ArcGIS, and the ArcGIS API for JavaScript. For more information about these clients, see Network analysis services .
To learn how to consume your network analysis service in ArcGIS for Desktop or a basic web application built with the ArcGIS API for JavaScript, see the sections below:
Consuming a routing service in ArcMap
- Start ArcMap and open a new blank ArcMap document.
- You should still have a publisher connection to ArcGIS Server, but you will need a user connection to consume this service in ArcMap. In the Catalog window, expand the GIS Servers node and double-click Add ArcGIS Server to begin making a user connection. For step-by-step instructions on setting up the connection, see Making a user connection to ArcGIS Server in ArcGIS for Desktop.
- In the Catalog window, expand the GIS Servers node and double-click your new ArcGIS Server connection, which ends with "(user)".
- Within your server connection, locate the map service that contains your network analysis service and drag it into the table of contents.
- Although the layer is present in the table of contents, the map is still blank. To provide context to your map, add a basemap layer from ArcGIS Online.
- Click the drop-down arrow next to the Add Data button on the Standard toolbar and choose Add Basemap.
- Double-click a basemap, such as Topographic.
- Zoom in to the San Francisco Peninsula, which is on the south side of the map, because the stops you are going to add need to fall within the bounds of the San Francisco network dataset that you used to create the network analysis layer. If you are not using the provided SanFrancisco database, you can skip this step.
- On the Tools toolbar, click Find Route.
- On the Find Route dialog box, click the Options tab.
- Click the Routing Service drop-down list and choose Route <Layers\[name of your route service]>.
- Click the Stops tab. Use the controls and parameters in the Stops tab to provide inputs to the network analysis.
- When you are ready to solve the route, click Find Route.
Consuming a routing service in a basic web application
- Before you can consume a network analysis service in a web application, you need to know its URL. In a web browser, navigate to the ArcGIS Server Services Directory, for example, http://gisserver.domain.com:6080/arcgis/rest/services.
- In the services list, click your network analysis service. All network analysis services are appended with (NAServer). If your service resides in a folder, navigate to that folder and select the service.
- A page displays showing the name of your service, service description, and a list of available analysis layers. Click Route.
- A page displays showing the properties of the route layer. In your browser's address bar, copy the URL of this page and paste it into a text editor. This is the REST URL to the route task of your network analysis service. The URL formats as follows: http://gisserver.domain.com:6080/arcgis/rest/services/folder/service/NAServer/Route.
- Copy and paste the sample code below into a text editor, such as Notepad.
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10"> <!--The viewport meta tag is used to improve the presentation and behavior of the samples on iOS devices--> <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"> <title>Simple Routing</title> <link rel="stylesheet" href="http://js.arcgis.com/3.6/js/dojo/dijit/themes/claro/claro.css"> <link rel="stylesheet" href="http://js.arcgis.com/3.6/js/esri/css/esri.css"> <script src="http://js.arcgis.com/3.6/"></script> <script> dojo.require("esri.map"); dojo.require("esri.tasks.route"); var map, routeTask, routeParams; var stopSymbol, routeSymbol, lastStop; function init() { map = new esri.Map("map", { basemap: "streets", center: [-122.44, 37.78], zoom: 12 }); dojo.connect(map, "onClick", addStop); routeTask = new esri.tasks.RouteTask("http://tasks.arcgisonline.com/ArcGIS/rest/services/NetworkAnalysis/ESRI_Route_NA/NAServer/Route"); //set up the route parameters routeParams = new esri.tasks.RouteParameters(); routeParams.stops = new esri.tasks.FeatureSet(); routeParams.outSpatialReference = {"wkid":102100}; dojo.connect(routeTask, "onSolveComplete", showRoute); dojo.connect(routeTask, "onError", errorHandler); //define the symbology used to display the route stopSymbol = new esri.symbol.SimpleMarkerSymbol().setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_CROSS).setSize(15); stopSymbol.outline.setWidth(4); routeSymbol = new esri.symbol.SimpleLineSymbol().setColor(new dojo.Color([0,0,255,0.5])).setWidth(5); } //Adds a graphic when the user clicks the map. If 2 or more points exist, route is solved. function addStop(evt) { var stop = map.graphics.add(new esri.Graphic(evt.mapPoint, stopSymbol)); routeParams.stops.features.push(stop); if (routeParams.stops.features.length >= 2) { routeTask.solve(routeParams); lastStop = routeParams.stops.features.splice(0, 1)[0]; } } //Adds the solved route to the map as a graphic function showRoute(solveResult) { map.graphics.add(solveResult.routeResults[0].route.setSymbol(routeSymbol)); } //Displays any error returned by the Route Task function errorHandler(err) { alert("An error occurred\n" + err.message + "\n" + err.details.join("\n")); routeParams.stops.features.splice(0, 0, lastStop); map.graphics.remove(routeParams.stops.features.splice(1, 1)[0]); } dojo.ready(init); </script> </head> <body class="claro"> <div id="map" style="width:600px; height:400px; border:1px solid #000;"></div> <p>Click on the map to add stops to the route. The route from the last stop to the newly added stop is calculated. If a stop is not reachable, it is removed and the last valid point is set as the starting point.</p> </body> </html>
- Locate the routeTask = new esri.tasks.RouteTask parameter and replace the URL in the parentheses to match the REST URL of your network analysis route task.
- Save and close the text document.
- Modify the file extension of the document to use .html instead of its native extension. For example, change Route.txt to Route.html.
- Open the HTML document with a web browser. Follow the instructions in the web application to use your network analysis service.