Supported with:
- Engine with Network
- ArcView with Network Analyst
- ArcEditor with Network Analyst
- ArcInfo with Network Analyst
- Server with Network
Library dependencies: System, SystemUI, Geometry, Display, Server, Output, Geodatabase, GISClient, ArcWeb, DataSourcesFile, DataSourcesGDB, DataSourcesOleDB, DataSourcesRaster, DataSourcesNetCDF, GeoDatabaseDistributed, GeoDatabaseExtensions, Carto, NetworkAnalysis, Location, GeoAnalyst, Animation, Maplex, GeoprocessingAdditional library information: Contents,
Object Model Diagram
The Network Analyst library provides objects for working with network datasets. These objects allow you to perform network analysis in your applications. The following diagram gives you an overview of some of the objects in the Network Analyst library.
The objects that implement this functionality are grouped into a number of library subsystems. These library subsystems are:The network analysis layer
NALayer is the topmost object in this set of objects. It is a true layer, capable of being persisted in ArcMap or on disk and accessed through ArcMap, ArcCatalog, Engine, or Server. NALayer is initially created by a solver through a call to
INASolver.CreateLayer. NALayer is the handle that other subsystems (ArcMap, Geoprocessing, ArcCatalog, Engine) use to reference a network analysis problem. From NALayer, it is possible to get NAContext and to NALayer's sub-layers that reference NAClass held by NAContext.
NAContext object is the most important object in this set of objects. As its name implies, it is the context that everything goes to for information. It has references to everything else that is used as part of the analysis. A context is generally created by calling
INASolver.CreateContext on a solver, then binding the context to a network dataset. The three main interfaces are as follows:
NAClass is a specialized feature class. It holds features representing things such as Stops, Barriers, Incidents, Facilities, Routes, CFRoutes, SALines, SAPolygons, ODLines, and so on. NAClass's workspace is NAContext and as such they are considered “in-memory” feature classes since they do not have a persistent source on disk other than when persisted within a layer file on disk. They can be retrieved in ways such as
INALayer.LayerByNAClassName(“Stops”).FeatureClass or by INAContext.NAClasses.ItemByName(“Stops”).
NAClasses serve up NALocationObject and
NALocationFeature, which are rows and features that can implement an additional interface,
INALocationObject, which specifies the position where it is located on the network.
The NAClassDefinition object has additional information about the class that is useful to the extension. It is initially set up by the solver when it creates NAContext and the contained NAClasses. It can be retrieved from NAClass by calling
INAClass.ClassDefinition.
INAClassDefinition has methods to determine the minimum and maximum number of rows required by the solver. It also specifies each field type, which can be any combination of input, output, not visible, and not editable.
Locating and loading
This subsystem represents objects used to load NAClasses representing
NALocation such as Stops, Barriers, and so on. Loading network locations entails starting with an input point, locating its position on the network by identifying the side and position along a feature in the network dataset, and creating a new feature in NAClass with this network position information. There are objects that do the locating (NALocator,
NALocatorFeatureAgent,
NALocatorLocationFieldsAgent) and objects that bulk load into NAClass based on NALocator (
NAClassLoader,
NAClassFieldMap).
If you have your own method for locating features and populating NAClass with the appropriate location information, you do not need to utilize the objects in this subsystem to load objects for you.
The NALocation object simply holds the place on the network where it’s located. The network location fields are as follows:
- SourceID is the SourceID of the feature class in the network dataset where the location is situated. You can get this ID from INetworkSource.ID.
- SourceOID is the ObjectID of the feature where the location is situated.
- SideOfEdge is either the right or left side.
- PosAlong specifies how far along the source feature (in the digitized direction) the network location is situated.
A default NALocator is created on NAContext by the solver when it creates NAContext. You can access and change the default locator for NAContext by setting the NALocator property on the INAContextEdit interface.
NALocator has a series of locator agents. It is the job of NALocator to iterate through the agents and determine which agent returned the best location. Most likely the agents will be NALocatorFeatureAgents. By default, NALocatorFeatureAgents are created for each network dataset source. Currently, only esriGeometryPartBoundary, esriGeometryPartMidpoint, and esriGeometryPartEndpoint are supported. The
SnapType property specifies where to snap along the geometry.
NALocator has a property,
SnapTolerance, that specifies the minimum search tolerance used when searching for network locations. If nothing is found within this tolerance, the search tolerance is doubled until a network location is found or the maximum search tolerance specified by
MaxSnapTolerance is reached.
The NALocatorLocationFieldsAgent object can be used if the source class already has location fields populated and you want to use these instead of spatially searching for the location on the network. Using precomputed network location fields significantly speeds up the loading process.
The NAClassLoader and NAClassFieldMap objects are used together to bulk load INALocationObject into NAClass from an input feature class using NALocator.
Solvers
A solver is an object that performs the actual network analysis. The four solvers distributed with ArcGIS are as follows:
Since it is the solver that knows what it requires to perform analysis (what type of network locations, what input properties, and so forth), it is the job of the solver to create NAContext and NALayer and to update them if any properties are changed. The general pattern to follow when creating a new analysis is to call
INASolver.CreateContext,
INASolver.Bind, and
INASolver.CreateLayer.
INASolver.Solve() performs network analysis based on the general and specific solver properties and network locations in NAContext. It returns:
- True if a partial solution has been found (e.g., some stops are unreachable but a partial route exists).
- False if the whole solution has been found.
Additionally, INASolver.Solve(NAContext,
GPMessages, TrackCancel) returns informational messages in the GPMessages object. Each GPMessage contains a description and may have naError code.
esriGPMessageTypes returned are:
- esriGPMessageTypeError when the solve fails (the analysis problem is incorrectly defined or the problem is unsolvable).
- esriGPMessageTypeWarning when a partial solution is found.
- esriGPMessageTypeAbort when the user aborts the analysis by pressing the ESC key.
As output, the solver populates output NAClasses that contain the results of the analysis. The following output NAClasses are populated by the solver when a partial or complete solution is found:
- Routes for NARouteSolver.
- CFRoutes for NAClosestFacilitySolver.
- SALines and SAPolygons for NAServiceAreaSolver.
- ODLines for NAODCostMatrixSolver.
The solver can also create a NATraversalResult object accessed through
INAResult that holds information about the network elements traversed during analysis. This information is necessary to perform post-processes such as generating driving directions after the route has been computed.
Traversal results
NARouteSolver, NAClosestFacilitySolver, and NAServiceAreaSolver output an NATraversalResult object that holds the results of the analysis. At its base level, the traversal result can be viewed as three feature classes that hold all the connectivity information about how the network elements were traversed:
- Edges—Includes each edge traversed during analysis. There are fields specifying FromJunction and ToJunction.
- Junctions—Includes each junction and input network location traversed.
- Turns—Includes each turn traversed.
The INAResult interface has methods to get the output properties and the context. There is a level of indirection in the NATraversalResult. Because of this, you must use methods on the
INATraversalResult interface to find the mapping between sources in the traversal result and the corresponding geodatabase or NAClass source.
INATraversalResultQuery is used to traverse from one traversal result element to another. You can call
SearchConnected to find the NATraversalResultElement connected to a specific TraversalResultElement. Or, since these are feature classes, you can get the feature class for all the traversal result elements of a specific type (e.g., edges) and open a search cursor on it.
NATraversalResult is not persisted with NAContext, and it is your responsibility to persist it to an external data structure if this is required.
Directions
Directions read NATraversalResults to construct driving directions as a post process to solving the route. You can retrieve
NAStreetDirectionsAgent from INAContext.get_Agents.get_ItemByName("StreetDirectionsAgent"). Once you have the agent, call
INAStreetDirectionsAgent.Execute passing in a set of the routes you want directions for, and it will generate directions.
Server objects
The Network Analyst objects all work within the server environment. There are a couple of additional objects and interfaces designed specifically for the server environment. The Network Analyst server objects can be accessed though the GIS Server application programming interface (API), GIS Client, and through a Web Service using Web Service Description Language (WSDL).
The general pattern when working with the server objects is as follows:
- Get a reference to an NAServer object either through a MapServer that has an NAServer extension loaded or through an NAServer Web service.
- Call INAServer.GetSolverParameters to get the INAServerSolverParams object holding the default parameters.
- Set properties on the NAServerSolverParams object to configure how you want the analysis to be performed.
- Set network locations (e.g., Stops) to use in the analysis.
- Call INAServer.Solve, passing in the INAServerSolverParams object.
- Use the returned NAServerSolverResults object to get at the results of the analysis.
The network location properties on the various NAServerSolverParams objects (for example, Stops, Barriers, Facilities, and Incidents) are of type
INAServerLocations. The INAServerLocations interface is the base interface of two other more specialized interfaces:
- The INAServerPropertySets interface provides access to an array of PropertySet objects. Each PropertySet represents a network location. Each property name and value represent a field name and value.
- The INAServerRecordSet interface provides access to a RecordSet object representing network locations.
INAServer.Solve performs network analysis based on the NAServerSolverParams object (NAServerRouteParams,
NAServerClosestFacilityParams,
NAServerServiceAreaParams) that was passed in and returns its output through a NAServerSolverResults object (
NAServerRouteResults,
NAServerClosestFacilityResults,
NAServerServiceAreaResults). INAServerSolverResults provides methods on an NAServerSolverResults object (NAServerRouteResults, NAServerClosestFacilityResults, NAServerServiceAreaResults) returned by the Solve method on INAServer to retrieve the results of the network analysis. For example, there is a method to get MapImage that will be populated if INAServerSolverParams.ReturnMap was set to True.
Different solvers return different NAServerSolverResults objects. For example, the results of route analysis will be an NAServerRouteResults object that supports the INAServerSolverResults and INAServerRouteResults interfaces.
Using Network Analyst in a server environment without NAServer
It is possible to create an application that bypasses NAServer and accesses the fine-grained Network Analyst objects on the server directly. When doing so, it is important to manage the state of the Network Analyst objects so other sessions aren't affected by changes to the objects. NAContext can be serialized to store all Network Analyst state information from one request to the other. For example, once you have a route displayed on the map, you will want to 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 finally restore NAContext, which has this information. Typically, during each use of a map server object (i.e., each request from the Web browser) the following steps take place for each Network Analyst layer with which you are working.
There is an
INALayer2 interface on the NALayer object that can be used in server applications to help manage the state of NALayer between sessions if it is necessary to use the fine grain network analyst objects. You do not need to use this if you are using NAServer. The general pattern is as follows:
- Use INALayer2.CopyContext to make a copy of the server's NALayer's NAContext. This is your local copy of the context that only your session will use.
- Prior to performing any network analysis, apply your local NAContext using INALayer2.AttachContext. This will be used to attach the server's NALayer to the NAContext specified.
- Set properties and call methods on any of the fine grain network analysis 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.
- When you're finished with the Web request, restore NALayer's original NAContext by calling INALayer2.AttachContext, passing in the original NAContext.