Calculate a service area

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:

ServiceAreaTask {
        id: serviceAreaTask
        url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/NetworkAnalysis/SanDiego/NAServer/ServiceArea"
    }

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 facilities.

NAFeaturesAsFeature {
    id: facilitiesFeatures
}

Graphic {
    id: facilityGraphic
    geometry: Point {
        x: -117.08
        y: 32.7
        spatialReference: {"wkid": 4326}
    }
    symbol: facilitySymbol
    Component.onCompleted : {
        facilitiesFeatures.addFeature(facilityGraphic);
    }
}

SimpleMarkerSymbol {
    id: facilitySymbol
    color: "turquoise"
    style: Enums.SimpleMarkerSymbolStyleSquare
    size: 8
    outline: SimpleLineSymbol {
        color: "black"
        width: 0.5
    }
}

ServiceAreaTaskParameters {
    id: serviceAreaTaskParameters
    facilities: 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
    ServiceAreaTaskParameters {
        id: taskParameters
        defaultBreaks: [5.0, 10.0, 15.0]
    }

The breaks you specify in the defaultBreaks 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 outputPolygons 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 splitPolygonsAtBreaks 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 overlapPolygons property. You can also join the polygons of multiple facilities that have the same break values by setting the mergeSimilarPolygonRanges property.

Line options

You can also generate service areas as lines instead of, or in addition to, polygons by setting the outputLines 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 splitLinesAtBreaks property. You can also generate overlapping or nonoverlapping lines by setting the overlapLines property.

Calculate service areas

Once you've initialized a ServiceAreaTaskParameters component with the desired input, finding the service areas simply requires a call to the solve method. The solveStatusChanged signal indicates the task's staus. When the status emitted is SolveStatusCompleted the results are available in the solvweResult property.

ServiceAreaTask {
        id: serviceAreaTask
        url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/NetworkAnalysis/SanDiego/NAServer/ServiceArea"
        Component.onCompleted: {
            serviceAreaTask.solve(serviceAreaTaskParameters)
        }
        onSolveStatusChanged: {
            if (solveStatus === Enums.SolveStatusCompleted)
            {
                 console.log("Solve complete");   
            }
            else if (solveStatus === Enums.SolveStatusErrored)
            {
                console.log("Solve error:" + solveError.message);
            }
        }
    }
    ServiceAreaResult {
        id:serviceAreaResult
    }