Summarize Within

Summarize Within

The Summarize Within task finds the point, line, or polygon features (or portions of these features) that are within the boundaries of polygons in another layer. For example:

  • Given a layer of watershed boundaries and a layer of land-use boundaries by land-use type, calculate total acreage of land-use type for each watershed.
  • Given a layer of parcels in a county and a layer of city boundaries, summarize the average value of vacant parcels within each city boundary.
  • Given a layer of counties and a layer of roads, summarize the total mileage of roads by road type within each county.

You can think of Summarize Within as taking two layers and stacking them on top of each other. One of the layers, the sumWithinLayer must be a polygon layer, and imagine that these polygon boundaries are all colored red. The other layer, the summaryLayer, can be any feature type—point, line, or polygon. After stacking these layers on top of each other, you peer down through the stack and count the number of features in the summaryLayer that fall within the polygons with the red boundaries (the sumWithinLayer). Not only can you count the number of features, you can calculate simple statistics about the attributes of the features in the summaryLayer, such as sum, mean, minimum, maximum, and so on.

Request URL

http://<analysis url>/SummarizeWithin/submitJob

Request Parameters

ParameterDescription

sumWithinLayer

(Required)

The polygon features. Features, or portions of features, in the summaryLayer (below) that fall within the boundaries of these polygons will be summarized.

Syntax: As described in detail in the Feature Input topic, this parameter can be

  • a URL to a feature service layer with an optional filter to select specific features, or
  • a feature collection.

Examples:

  • {"url": <feature service layer url>, "filter": <where clause>}
  • {"layerDefinition": {}, "featureSet": {}, "filter": <where clause>}

summaryLayer

(Required)

Point, line, or polygon features that will be summarized for each polygon in the sumWithinLayer.

Syntax: As described in detail in the Feature Input topic, this parameter can be

  • a URL to a feature service layer with an optional filter to select specific features, or
  • a feature collection.

Examples:

  • {"url": <feature service layer url>, "filter": <where clause>}
  • {"layerDefinition": {}, "featureSet": {}, "filter": <where clause>}

sumShape

A Boolean value that instructs the task to calculate statistics based on shape type of the summaryLayer, such as the length of lines or areas of polygons of the summaryLayer within each polygon in sumWithinLayer. The default is true.

Values: true | false

shapeUnits

Values:

  • When summaryLayer contains polygons: Acres | Hectares | SquareMeters | SquareKilometers | SquareMiles | SquareYards | SquareFeet
  • When summaryLayer contains lines: Meters | Kilometers | Feet | Yards | Miles

Example:

  • "shapeUnits": "Hectares"

summaryFields

A list of field names and statistical summary type that you wish to calculate for all features in the summaryLayer that are within each polygon in the sumWithinLayer .

Syntax: ["fieldName summaryType","fieldName summaryType", ...]

fieldName is the name of one of the numeric fields found in the summaryLayer

summaryType is one of the following:

  • Sum - Adds the total value of all the features in each polygon
  • Mean - Calculates the average of all the features in each polygon.
  • Min - Finds the smallest value of all the features in each polygon.
  • Max - Finds the largest value of all the features in each polygon.
  • Stddev - Finds the standard deviation of all the features in each polygon.

Example:

  • "summaryFields": ["Annual_Sales Sum", "Annual_Sales Mean"]

groupByField

This is a field of the summaryLayer features that you can use to calculate statistics separately for each unique attribute value. For example, suppose the sumWithinLayer contains city boundaries and the summaryLayer features are parcels. One of the fields of the parcels is Status which contains two values: VACANT and OCCUPIED. To calculate the total area of vacant and occupied parcels within the boundaries of cities, use Status as the groupByField field.

Example:

  • "groupByField": "Status"

When a groupByField field is provided, the service returns a table containing the statistics in the groupBySummaryoutput parameter.

minorityMajority

This boolean parameter is applicable only when a groupByField is specified. If true, the minority (least dominant) or the majority (most dominant) attribute values for each group field are calculated. Two new fields are added to the resultLayer prefixed with Majority_ and Minority_.

The default is false.

Values: true | false

percentShape

This Boolean parameter is applicable only when a groupByField is specified. If set to true, the percentage of each unique groupByField value is calculated for each sumWithinLayer polygon. The default is false.

Values: true | false

outputName

If provided, the task will create a feature service of the results. You define the name of the service. If outputName is not supplied, the task will return a feature collection.

Syntax:
{
  "serviceProperties": {
    "name": "<service name>"
  }
}

context

Context contains additional settings that affect task execution. For Summarize Within, there are two settings.

  1. Extent (extent)—a bounding box that defines the analysis area. Only those features in the sumWithinLayer and the SummaryLayer that intersect the bounding box will be summarized.
  2. Output Spatial Reference (outSR)—the output features will be projected into the output spatial reference.
Syntax:
{
"extent" : {extent}
"outSR" : {spatial reference}
}

f

The response format. The default response format is html.

Values: html | json

Response

When you submit a request, the service assigns a unique job ID for the transaction.

Syntax:
{
"jobId": "<unique job identifier>",
"jobStatus": "<job status>"
}

After the initial request is submitted you can use the jobId to periodically check the status of the job and messages as described in the topic Checking job status. Once the job has successfully completed, you use the jobId to retrive the results. To track the status, you can make a request of the following form:

http://<analysis url>/SummarizeWithin/jobs/<jobId>

Accessing results

When the status of the job request is esriJobSucceded, you can access the results of the analysis by making a request of the following form.

http://<analysis url>/SummarizeWithin/jobs/<jobId>/results/<output parameter name>?token=<your token>&f=json

ParameterDescription

resultLayer

These are the polygon features of the sumWithinLayer with summary statistics about the features in the summaryLayer that fall within each polygon.

Example:
{"url": 
"http://<analysis url>/SummarizeWithin/jobs/<jobId>/results/resultLayer"}

The result has properties for parameter name, data type, and value. The contents of value depends upon the outputName parameter provided in the initial request.

  • If outputName was provided, value contains the url to the feature service layer.

    {
    "paramName":"resultLayer", 
    "dataType":"GPString",
    "value":{"url":"<hosted featureservice layer url>"}
    }

  • If outputName was not provided, value contains a feature collection.

    {
    "paramName":"resultLayer",
    "dataType":"GPString",
    "value":{"layerDefinition": {}, "featureSet": {}}
    }

See Feature Output for more information about how the result layer or collection is accessed.

groupBySummary

If a groupByField field was provided as input, the result will have a groupBySummary table that contains the caclulated statistics for each unique group. Tables are simply a subset of features; that is, they contain attributes but no geometry.

Example:

{"url": 
"http://<analysis url>/SummarizeWithin/jobs/<jobId>/results/groupBySummary"}

The result has properties for parameter name, data type, and value. The contents of value depends upon the outputName parameter provided in the initial request.

  • If outputName was provided, value contains the url to the feature service layer.

    {
    "paramName":"groupBySummary", 
    "dataType":"GPString",
    "value":{"url":"<hosted featureservice layer url>"}
    }

  • If outputName was not provided, value contains a feature collection.

    {
    "paramName":"groupBySummary",
    "dataType":"GPString",
    "value":{"layerDefinition": {}, "featureSet": {} }
    }