Tutorial: Perform an analysis with a raster operation

Learn how to perform a raster analysis with raster operations.

Zonal Statistics

A zonal statistics operation calculates statistics on cell values of a raster within the zones defined by another dataset. The types of statistics you can calculate include Mean, Majority, Maximum, Median, Minimum, Minority, Sum, Percentile, Range, and Standard deviation.

Common use cases for performing a zonal statistics operation are:

  • Summarizing land cover types within administrative boundaries.
  • Analyzing elevation statistics within zones.
  • Summarizing soil properties within agricultural fields.
  • Analyzing vegetation indices within ecological Zones.

In this tutorial, you use the SummarizeRasterWithin and ConvertRasterToFeature operations to find the average annual temperature for each of the 67 counties in Alabama and then convert the output imagery layer to a feature service. You can perform the summarize analyses either in Map Viewer or programmatically using the ArcGIS API for Python, ArcGIS REST JS, and ArcGIS REST APIs.

The analyses include:

  • Calculating the mean temperature value for each feature in a feature service.
  • Creation of a new hosted imagery layer containing the results of the analysis.

Prerequisites

You need an ArcGIS Online or ArcGIS Enterprise with the proper privileges to perform raster analysis.

Steps

Copy the web map

The tutorial web map contains predefined layers to use as the starting point for the analyses outlined in the steps below.

  1. Go to the Zonal statistics tutorial data web map and click Sign in.
  2. Verify that you have the following layers by toggling the visibility on and off:
    • Graffiti cases within San Francisco
    • Census blocks in three neighborhoods SF
  3. Click Save > Save As > Save Map to save a copy.

Calculate zonal statistics

The County boundaries hosted feature layer from the ArcGIS Living Atlas contains all the county polygons in the United States. A filter expression has been applied to limit the counties processed to Alabama. The US Annual Temperature hosted imagery layer contains average temperature values across the United States. Use the SummarizeRasterWithin operation to calculate the average temperature of each county.

Steps to use the Map ViewerSteps to use scripting APIs
  1. In the right side bar, click the Analysis tool to open the analysis pane.

  2. Click Tools to open the list of available tools and type in Zonal Statistics in the search bar.

  3. Click on Zonal Statistics to open the tool window.

  4. Set the following input layer parameters:

    • Input zone raster of features: County boundaries The count of features should be 67
    • Zone field: County FIPS
    • Input value raster: US annual temperature
  5. Set the following statistical analysis settings parameters:

    • Stastic type: Mean
    • Add a check to the Ignore NoData parameter.
  6. Set the Result layer parameters to:

    • Output raster name: Zonal statistics tutorial result
    • Output layer type: Tiled imagery layer
  7. Click on Estimate credits. The analysis will consume USD $0.11 (1.13) credits.

  8. Click the Run button to start the analysis. After a short period of time an alert should display indicating the analysis has been submitted.

  9. Click the History button in the top right of the Analysis pane to view the progress of the analysis.

  10. Once the analysis has completed, the result layer will be added to the map.

A new tiled imagery layer will be created in your portal with the analysis result.

APIs

The general steps for performing the analysis programmatically are:

  1. Implement user authentication to access the raster analysis service.
  2. Define the parameters of the request.
  3. Make the request. Note: This is a long transaction managed with a job request.
  4. Handle the results.
ArcGIS API for PythonArcGIS API for PythonArcGIS REST JS
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# USA County layer from living atlas
zone_layer_item = portal.content.get("14c5450526a8430298b2fa74da12c2f4")
zone_layer = zone_layer_item.layers[0]
# filter this layer on a specific state name
zone_layer.filter = "STATE_NAME='Alabama'"

# annual temperature raster layer item
raster_layer_item = portal.content.get("a8b93a96c7224a69a5b387722b89a6ee")
raster_layer = raster_layer_item.layers[0]

# perform the operation
summarized_layer = summarize_raster_within(
    input_zone_layer=zone_layer,
    input_raster_layer_to_summarize=raster_layer,
    zone_field="COUNTY_FIPS",
    statistic_type="Mean",
)
print(f"Summarize raster within hosted imagery layer created {summarized_layer.itemid}")

Service requests

Request
HTTPHTTPcURL
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

POST https://www.arcgis.com/sharing/rest/portals/self HTTP/1.1
Content-Type: application/x-www-form-urlencoded

token={ACCESS_TOKEN}
f=json
Response (JSON)
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

{
  "helperServices": {
    // Other parameters
    "rasterAnalytics": {
      "url": "https://<YOUR_ANALYSIS_SERVICE>/arcgis/rest/services/tasks/GPServer"
    },
    "geoenrichment": {
      "url": "https://geoenrich.arcgis.com/arcgis/rest/services/World/GeoenrichmentServer"
    }
    // Other parameters
  }
}

Convert the result layer

Steps to use the Map ViewerSteps to use scripting APIs
  1. In the right side bar, click the Analysis tool to open the analysis pane.

  2. Click Tools to open the list of available tools and type in Convert Raster to Feature in the search bar.

  3. Click on Convert Raster to Feature in the result list to open the tool window.

  4. Set the following Input layer parameters:

    • Input raster layer to convert: Zonal statistics tutorial result This will be the imagery layer you generated in the step above
  5. Set the following Conversion settings parameters:

    • Field to convert: Value
    • Output type: Polygon
    • Simplify lines of polygons: true
    • Create multipart features: true
  6. Set the Result layer parameters to:

    • Output raster name: Converted zonal statistics result
  7. Click on Estimate credits. The analysis will consume USD $0.10 (1 credit).

  8. Click the Run button to start the analysis. After a short period of time an alert should display indicating the analysis has been submitted.

  9. Click the History button in the top right of the Analysis pane to view the progress of the analysis.

  10. Once the analysis has completed, the result layer will be added to the map.

A new hosted feature layer will be created in your portal with the analysis result.

APIs

The general steps for performing the analysis programmatically are:

  1. Implement user authentication to access the raster analysis service.
  2. Define the parameters of the request.
  3. Make the request. Note: This is a long transaction managed with a job request.
  4. Handle the results.
ArcGIS API for PythonArcGIS API for PythonArcGIS REST JS
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

# Input raster layer
input_raster_item = portal.content.get("c04d376b57484a6685163f56f209063c")
input_raster_layer = input_raster_item.layers[0]

# perform the operation
converted_layer = convert_raster_to_feature(
  input_raster=input_raster_layer,
  field="Value",
  output_type="Polygon",
  simplify=True,
  create_multipart_features=True,
  output_name="Converted zonal statistics python")

print(f"Converted raster layer to feature layer created {converted_layer.itemid}")

Service requests

Request
HTTPHTTPcURL
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

POST https://www.arcgis.com/sharing/rest/portals/self HTTP/1.1
Content-Type: application/x-www-form-urlencoded

f=json
&token={ACCESS_TOKEN}
Response (JSON)
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

{
  "helperServices": {
    // Other parameters
    "rasterAnalytics": {
      "url": "https://<YOUR_ANALYSIS_SERVICE>/arcgis/rest/services/tasks/GPServer"
    },
    "geoenrichment": {
      "url": "https://geoenrich.arcgis.com/arcgis/rest/services/World/GeoenrichmentServer"
    }
    // Other parameters
  }
}

What's next?

Learn how to perform raster analysis with raster functions:

Create a raster function template

Perform a raster analysis with a raster function template.


Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.