Using Network Analyst objects


In this topic


The Network Analyst objects

All of the Network Analyst objects in the com.esri.arcgis.networkanalyst package work in the server environment if the user explicitly manages their state. Most users, however, use the Network Analyst server objects that were designed specifically for the server environment. These stateless objects provide coarse-grained network analysis functionality. The Network Analyst server objects can be accessed though the Server application programming interface (API), the GISClient API, and through a Web service Simple Object Access Protocol (SOAP) API using Web Service Description Language (WSDL).

Using the coarse-grained stateless server objects (NAServer)

The NAServer object is a MapServer server object extension that can perform network analysis through a single stateless method call. It is used in conjunction with various NAServerSolverParams and NAServerSolverResults objects.
Follow these steps when working with the server objects:
  1. Get a reference to an NAServer object, either through a MapServer that has an NAServer extension loaded, or through an NAServer Web service.
  2. Call NAServer.getGetSolverParameters to get the NAServerSolverParams object holding the default parameters.
  3. Set properties on the NAServerSolverParams object to configure how you want the analysis to be performed.
  4. Set network locations (e.g., Stops) to use in the analysis.
  5. Call NAServer.solve passing in the NAServerSolverParams object.
  6. Use the returned NAServerSolverResults object to obtain the results of the analysis.
You can use the following methods to get additional information:
  • NAServer.getNALayerNames—Retrieves the name of the analysis layer(s) in the map for a particular type if you don't already know the name.
  • NAServer.getNetworkDescription—Obtains information about the network dataset that a particular network analysis layer is referencing. This includes the network dataset's name, attributes, and sources.
All NAServerSolverParams objects support INAServerSolverParams and INASolverSettings. The INAServerSolverParams interface allows you to specify general properties such as the MaxSnapTolerance, ReturnMap, OutputSpatialReference. There are also specific interfaces for each type of solver. For example, NAServerRouteParams also supports INAServerRouteParams and INARouteSolver.
With the WSDL generated proxy objects, all the methods are directly on the base objects and these other interfaces are not necessary.
The network location properties on the various NAServerSolverParams objects—for example, Stops, Barriers, Facilities, and Incidents—are of type NAServerLocations, which is the base of the following specialized objects:
  • NAServerPropertySets—Provides access to an array of PropertySet objects. Each property set represents a network location. Each property name and value represent a field name and value.
  • NAServerRecordSet—Provides access to a RecordSet object representing network locations.
NAServer.solve performs network analysis based on the NAServerSolverParams object (NAServerRouteParams, NAServerClosestFacilityParams, NAServerServiceAreaParams) that was passed in and returns its output through an NAServerSolverResults object.
The NAServerSolverResults object (NAServerRouteResults, NAServerClosestFacilityResults, NAServerServiceAreaResults) returned by the NAServer.solve method is used to access the results of the network analysis. For example, there is a method to get the MapImage that will be populated if INAServerSolverParams.isReturnMap is set to True.
Different solvers return different objects all derived from NAServerSolverResults. The result of a route analysis will be an NAServerRouteResults object. For closest facility analysis, it will be an NAServerClosestFacilityResults object. For service area analysis, it will be an NAServerServiceAreaResults object.
All the solver result objects include various methods to retrieve the resulting network analysis classes as RecordSet objects and resulting geometries as simple geometries. For the NAServerRouteResults and NAServerClosestFacilityResults objects, you can also retrieve the NAStreetDirections and NAStreetDirection objects for displaying driving directions.

Using the fine-grained Network Analyst objects requiring state management

It is possible to create an application that bypasses NAServer and directly accesses the fine-grained Network Analyst objects on the server. When you do this, ensure that you manage the state of the Network Analyst objects so other sessions aren't affected by changes to the objects. The NAContext object can be serialized to store all Network Analyst state information from one request to another. For example, once you have a route displayed on the map, you can continue to display that route even after the map has been panned or zoomed. For each request to your application, a process occurs to retrieve, store, copy or apply, serialize, and restore the NAContext object that has this information. Typically, during each use of a map server object (that is, each request from the Web browser), the following steps take place for each Network Analyst layer with which you are working.
You can use the interface INALayer2 on the NALayer object in server applications to help manage the state of NALayer between sessions if it is necessary to use the fine-grained Network Analyst objects. You do not need to use this if you are using NAServer. The general pattern is as follows:
  1. Use NALayer.copyContext to make a copy of the server NALayer NAContext. This is your local copy of the context that only your session will use.
  2. Prior to performing any network analysis, apply your local NAContext using NALayer.attachContext. This is used to attach the server's NALayer to the NAContext specified.
  3. Make method calls on any of the fine-grained Network Analyst objects. You can also call methods that draw, perform spatial searches, or anything else that requires your NAContext be attached to the server's NALayer.
  4. When you're finished with the Web request, restore the NALayer original NAContext by calling NALayer.attachContext passing in the original NAContext.


See Also:

Working with networks
Managing state in a Network Analyst application