Skip To Content

Calculate a service area

In this topic

A service area task allows you to calculate areas that can be serviced (reached) from a given location using ArcGIS Network Analyst services.

A Network Analyst service contains one or more network analysis layers. ArcGIS provides different types of network analysis layers, such as route, service area, closest facility, and so on, depending on the type of analysis performed. A service area task relies on a service area analysis layer.

Learn about creating Network Analyst services

Create a service area task

To instantiate a service area task, provide a URL to the REST resource that represents a service area layer in a Network Analyst service. If the service is secured, provide the credentials used to access the service. The following code snippet shows how to create a service area task for the service area layer in the San Diego, CA, service on an ArcGIS Online sample server:

// Construct a service area task
static const QString urlNaSanDiego = 
  "http://sampleserver6.arcgisonline.com/arcgis/rest/services/NetworkAnalysis/SanDiego/NAServer/ServiceArea";
m_serviceAreaTask = new EsriRuntimeQt::ServiceAreaTask(urlNaSanDiego, this);

Prepare the input

Provide input to the service area task using an object of the ServiceAreaTaskParameters class. Instantiate a new ServiceAreaTaskParameters object, and modify its properties to provide the input.

The following sections describe some of the inputs you can provide to a service area task.

Facilities

Facilities represent locations from which service areas need to be calculated. For example, a fire station can be set as a facility to find areas it can serve within a 10-minute service area. A hospital can be set as the facility to determine what proportion of the population is within a two-mile driving distance.

Features

You can create an array of objects representing facility features. You can then assign these features to the parameter object using setFacilities.

// Create a collection of facilities Graphic elements
QList<EsriRuntimeQt::Graphic*> m_facilities;
EsriRuntimeQt::Point pt(-117.08, 32.7, m_map->spatialReference());
EsriRuntimeQt::Graphic* graphic = new EsriRuntimeQt::Graphic(
      pt, EsriRuntimeQt::TextSymbol(QColor("black"),
      8, QString::number(m_facilities.size()+1)), this);
m_facilities.append(graphic);

// Convert the Graphics to NAFeatures
EsriRuntimeQt::NAFeaturesAsFeature* facilitiesFeatures = new EsriRuntimeQt::NAFeaturesAsFeature(this);
facilitiesFeatures->setSpatialReference(m_map->spatialReference());
facilitiesFeatures->setFeatures(m_facilities);

// Set the facilities features to the ServiceAreaTaskparameters
EsriRuntimeQt::ServiceAreaTaskParameters* parameters = new EsriRuntimeQt::ServiceAreaTaskParameters(this);

parameters->setFacilities(facilitiesFeatures);

Breaks

Breaks specify the quantity of the impedance to apply. They constrain the extent of the service area to calculate. For example, if you apply breaks of 5, 10, and 15 when the impedance is set to Time, the service area includes all those streets that can be reached within 5, 10, and 15 minutes.

// Construct a ServiceAreaTaskParameters and set default breaks
EsriRuntimeQt::ServiceAreaTaskParameters* parameters = new EsriRuntimeQt::ServiceAreaTaskParameters(this);
parameters->setDefaultBreaks(QList<double>() << 5.0 << 10.0 << 15.0);

The breaks you specify in the setDefaultBreaks property are applied to all facilities that don't contain their breaks. If you're computing service areas for several facilities in a batch, provide different breaks for each facility by setting their attributes accordingly.

Result options

The following discusses result options.

Polygon options

You can generate service areas as detailed or simplified polygons by setting the setOutputPolygons property on ServiceAreaTaskParameters. Detailed polygons take significantly longer to generate but more accurately represent the service area. Simplified polygons can be generated quickly and are reasonably accurate, except at the outer edges. If your data is of an urban area with a grid network, the difference between generalized and detailed polygons is minimal. However, for mountain and rural roads, the detailed polygons may present significantly more accurate results than generalized polygons.

If you use more than one break for generating service areas, you can create concentric service area polygons as disks or rings by setting the setSplitPolygonsAtBreaks property. Rings are created when you set the property to True. Rings do not include the area of smaller breaks. This creates polygons going between consecutive breaks. Disks are polygons going from a facility to a break. If you create 5- and 10-minute service areas, the 10-minute service area polygon includes the area under the 5-minute service area polygon, as well as the area from the 5-minute to the 10-minute break.

If you include multiple facilities in the analysis, you can also generate overlapping or nonoverlapping polygons by setting the setOverlapPolygons property. You can also join the polygons of multiple facilities that have the same break values by setting the setMergeSimilarPolygonRanges property.

Line options

You can also generate service areas as lines instead of, or in addition to, polygons by setting the setOutputLines property on ServiceAreaTaskParameters. Lines can be straight or true shape. Straight lines are based on "as the crow flies" directions, whereas true shape lines follow the underlying transportation network.

As with polygons, you can split lines that span multiple breaks by setting the setSplitLinesAtBreaks property. You can also generate overlapping or nonoverlapping lines by setting the setOverlapLines property.

Calculate service areas

Once you've initialized a ServiceAreaTaskParameters object with the desired input, finding the service areas simply requires a call to the solve method. The ServiceAreaTask transmits its results using the serviceAreaTaskCompletesignal that can be connected to a slot that is called whenever a service area task has finished executing. The operation's results are contained in a ServiceAreaResult object. Making this asynchronous call will keep the application's UI thread free and responsive while the task is working on a separate thread of execution.

Alternatively, the solveAndWait method can be called, which will make a synchronous call to the server. This means that the application will block the application's UI thread until the ServiceAreaTask is finished. If the solveAndWait method is used, a ServiceAreaTaskResult is returned and there is no need for a callback method to handle it.

// Execute the solve asynchronously
m_serviceAreaTask->solve(parameters);
// ...

// Slot to handle serviceAreaTaskComplete signal
void MainWindow::onServiceAreaTaskComplete(EsriRuntimeQt::ServiceAreaResult* result)
{
  QList<EsriRuntimeQt::NAMessage> messages = result->messages();
  EsriRuntimeQt::FeatureSet* fset = result->serviceAreaPolygons();
    
  // Now use these polygons, for example, by adding them to a layer in the map.
  //...
  
  // make sure the result is deleted
  result->deleteLater();
}