Generate service areas

In this topic

You can do the following using the ArcGIS Runtime SDK service area task:

Find all roads that can be reached within a given distance or time from a specific location

Request multiple service areas cutoffs for one or more locations

Specify how service areas from multiple locations are constructed

Use different travel modes to model various transportation scenarios

This topic describes how to generate service areas from an online network service. For an overview of networks and network analysis, see What is a network dataset in the ArcGIS Desktop documentation.

Choosing a data source

The service area task supports using online services or a local mobile geodatabase as its data source for a network.

Use an online network service

To model service area boundaries for a set of facilities, you can use a transportation network exposed as an online ArcGIS service (an ArcGIS network analysis service). Network analysis services are hosted in Esri's cloud platform, ArcGIS Online, or can be published on your own ArcGIS servers. These services provide a REST API for clients such as mobile and web applications. For more information about publishing a service, see Tutorial: Publishing a network analysis service.

The most important criterion for choosing a service is the geographic extent that it covers. You cannot find service areas using a service that does not encompass the street network used by the facilities. In addition, services offer differing levels of capability and specialization, which are determined by the service properties and the underlying transportation network dataset.

You can build a transportation network dataset from your own data, or use a dataset provided by someone else, such as Esri's World Street Map data. Then, you can publish the data as a service area service on your own portal or on ArcGIS Online. Or, you can use a service area service created by someone else that suits your needs, such as the Esri World Service Area Service, which references data that covers much of the world. Since the ArcGIS Online data also includes traffic for many areas, analysis can account for dynamic traffic conditions. For instance, you can generate service areas for 7:00 a.m. and compare them with those you generate for 8:00 a.m.

Accessing a service area service may require authorization, which is also true for accessing map and feature services. You can authorize by providing valid credentials when you create the service area task object or by adding a token to the AuthenticationManager. For more information, see Use the Authentication Manager.

When using ArcGIS Enterprise portal, default utility services may be configured, such as a service area service. ArcGIS Runtime API provides methods to obtain the default service's URL for a given portal. Setting a default service on a portal is optional, however, so it may not always be set.

Use local data

You can find service areas using a transportation network stored on your device, meaning that your device does not need a network connection to a communication network to find a service area. You have a couple of options for provisioning your device with a local transportation network: mobile geodatabases or mobile map packages. Either may be deployed with your app on the device.

If you'd like a ready-to-use and regularly updated network dataset (and locator) for your area of interest, you can license StreetMap Premium data (in mobile map package format). For details, see Add StreetMap Premium data.

You can also create a service area task from a mobile map package or mobile geodatabase stored on the device.

// open a local mobile map package (.mmpk file)
MobileMapPackage mmpk = await MobileMapPackage.OpenAsync(mapPackagePath);
// load the first map in the package
Map firstMap = mmpk.Maps[0];
await firstMap.LoadAsync();
// create a service area task from the first transportation network in the map
ServiceAreaTask task = await ServiceAreaTask.CreateAsync(firstMap.TransportationNetworks[0]);

// create a service area task from a mobile geodatabase (.geodatabase) and network name
ServiceAreaTask task = await ServiceAreaTask.CreateAsync(geodatabasePath, "Streets_ND");

Specify service area task parameters

Service area task parameters specify how the analysis should be performed. There are many parameters that let you customize how the service area is determined. Parameters include facilities, barriers, travel mode, impedance cutoffs, polygon detail, and so on.

You can get the default set of service area task parameters from the service area task object. These default parameters are determined by properties of the service and the underlying transportation network dataset. Often, different services have different defaults. Rather than building task parameters from scratch, it's recommended to start with the default parameters for the service and to then modify the individual parameter values you want to change.

The following example gets the default ServiceAreaParameters and changes some of the parameter values.

Your app might allow users to choose some parameters, such as cost attributes to accumulate or the polygon buffer distance. Your app would get these choices from the user and set the corresponding values on the parameter object.

Specify facilities and barriers

Facilities are points features. They can be created either explicitly from MapPoint objects or by specifying a feature table (local or online) with a geometry of type point. When using a feature table you can optionally set a where clause to filter which features to use. When specifying an online feature table, the table will not be queried until solve is called.

Barriers are locations along the network that either restrict travel completely (a road closure for example) or add to the cost of travel when traversed (road work or increased traffic for example).

Barriers can be points, polylines, or polygons, and you can define barriers in various ways. Your users might draw barrier graphics interactively, your app might load graphics from a feature table, and so on. For example, you may have a feature table with areas affected by a forest fire that must be avoided. Barriers are optional when solving for service areas but when relevant, can make your results more accurate.

The solve operation projects input features to the spatial reference of the transportation network dataset used by the service. The spatial reference of the facilities and barriers must be defined but can be different than the transportation network dataset's spatial reference.

The following example creates facilities and barriers and uses them to set properties on the service area parameters:

// open a service table of facilities
Uri facilityTableUri = new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/NetworkAnalysis/SanDiegoInputs/MapServer/3");
ServiceFeatureTable facilityServiceTable = new ServiceFeatureTable(facilityTableUri);
// create query parameters to select all facilities
QueryParameters facilityQueryParams = new QueryParameters();
facilityQueryParams.WhereClause = "1=1";
// set the task parameters facilities using the table and the query parameters
parameters.SetFacilities(facilityServiceTable, facilityQueryParams);

The following example uses a local table to define facilities:

// open a local runtime geodatabase with tables for task inputs
var geodatabasePath = @"c:\data\mydata.geodatabase";
var gdb = await Geodatabase.OpenAsync(geodatabasePath);
// get the table that contains facility features
ArcGISFeatureTable facilityTable = gdb.GeodatabaseFeatureTable("Facilities");
// create a query parameters that filters for hospitals and fire stations
var facilityQueryParams = new QueryParameters();
facilityQueryParams.WhereClause = "Type='Hospital' or Type='Fire Station'";
// set the parameters facilities using the local table and query
parameters.SetFacilities(facilityTable, facilityQueryParams);

Note:

The input table's field values can be used to populate properties for facilities and barriers. For local geodatabases, this is based on a naming convention. For details, see Service area analysis. When publishing a service area service, the default names can be altered. For details, see Loading Network Analysis Objects in ArcMap

Other service area parameters properties

The following are the properties that can be set on the parameter's object to further refine how service areas are determined:

Default impedance cutoffs—This property specifies the values used to calculate the extent of the service areas. The inputs are in the units of the impedance cost attribute defined for the network travel mode being used.

The default impedance cutoffs can be overridden on specific facilities by specifying the impedance cutoffs on a facility. The exception to this is when the geometry at overlap parameter is set to dissolve, in which case, the facilities cutoffs are ignored and the default impedance cutoff is used. This is to ensure all facilities have the same cutoff values, and the service areas polygons can be dissolved. This behavior is applied even if only a single facility is specified and service area overlap geometry dissolve is specified.

Polygon buffer distance—This property specifies the distance, in meters, by which the outer service area polygons will be trimmed. This is useful if the network is sparse and you don't want the service area to cover large areas where there are no network features.

Service area polygon detail—The level of detail of the output polygon geometry can be specified by setting this property. The higher the requested detail, the more accurate the output but the longer it will take to generate. The following list describes the available values for this property.

Generalized

Generated quickly

Fairly accurate (deteriorates near service area polygon boarders)

Polygons are simplified

May result in islands of unreached elements being included in the service area

Hierarchical solve used

Polygons cannot be trimmed

Polylines cannot be returned

Standard

Generated fairly quickly

Polygons are simplified

Hierarchical solve not used

Polygons can be trimmed using the polygon buffer distance parameter

Polylines can be returned

High

Longer to generate

More accurate

Polygons are more detailed

Hierarchical solve not used

Polygons can be trimmed using the polygon buffer distance parameter

Polylines can be returned

Geometry at overlap—This property controls how the overlapping polygons are constructed when multiple facilities are specified. The three options are as follows:

Dissolve—Overlapping polygons with the same cutoff values are merged

Overlap—Polygons are created for each facility independently and may overlap

Split—Overlaps between polygons are assigned to a single facility based on the lowest impedance

Geometry at cutoffs—Controls how the output polygons are constructed. If geometry at cutoffs is set to Rings, the output polygons will not include the area of smaller inner cutoffs. If geometry at cutoffs is set to Disks, the output polygons will include the area of smaller inner cutoffs.

Return polylines—Lines will only be returned when polygon detail is set to Standard or High. The polylines will be split at the cutoff boundaries.

Execute the service area task

Execute the service area task's solve method, providing the service area parameters.

Process results

When the service area task completes, results are available as a service area result. Depending on the success of the task, the Messages property on the result object may be populated. These messages contain information about how the task was solved.

The outputs can include polygons, polylines, facilities, and barriers depending on the service area parameter settings. The output facilities and barriers are copies of the corresponding inputs and have information such as location status or distance to network location populated by the solve process.

Service area polygons

To access the resulting service area polygons, you can iterate through the returned facilities and get a list of service area polygons for each facility. The shape and size of these polygons are affected by the service area parameter values passed in to the solve operation.

// loop through all facilities in the result
int facilityIndex = 0;
foreach (ServiceAreaFacility f in solveResult.Facilities)
{
// get the result polygons (service areas) for this facility
IEnumerable<ServiceAreaPolygon> serviceAreas = solveResult.GetResultPolygons(facilityIndex);
if (serviceAreas != null)
{
// loop through all service areas for this facility
foreach (var area in serviceAreas)
{
// create a fill symbol
var symbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, GetColor(), null);
// add a new graphic to display the service area (in a graphics overlay)
resultOverlay.Graphics.Add(new Graphic(area.Geometry, symbol));
}
}
facilityIndex++;
}

Service area polylines

To access the polylines, iterate through the returned facilities and retrieve the list of the network polylines that are within each facility's service areas. The cumulative from and to costs can be retrieved from each polyline.

// loop through all facilities in the result
for (int i = 0; i < solveResult.Facilities.Count; i++)
{
// loop through the polyline results for this facility
foreach (ServiceAreaPolyline serviceAreaPolyline in solveResult.GetResultPolylines(i))
{
// get the cost of traveling this line using the travel mode
double toCost = serviceAreaPolyline.GetToCumulativeCost(parameters.TravelMode.ImpedanceAttributeName);
// ... work with polyline results, summarize costs, and so on ...
}
}