# Summarize Within (Analysis)

## Summary

Overlays a polygon layer with another layer to summarize the number of points, length of the lines, or area of the polygons within each polygon, and calculate attribute field statistics about the features within the polygons.

Example scenarios using Summarize Within:

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

## Usage

• Think of Summarize Within as taking two layers, the input polygons and the input summary features, and stacking them on top of each other. After stacking these layers, look down through the stack and count the number of input summary features that fall within the input polygons. Not only can you count the number of features, you can calculate simple statistics about the attributes of the input summary features, such as sum, mean, minimum, maximum, and so on.

• The Summarize Within and Summarize Nearby tools are conceptually similar. With the Summarize Within tool, you can summarize features within existing polygons. With the Summarize Nearby tool, you can generate areas around points, lines, or polygons, and summarize features within those derived areas.

• You can create groups by specifying a group field from the input points. For example, if you are summarizing crimes within neighborhood boundaries, you may have a Crime_type attribute with five different crime types. Each unique crime type forms a group, and the statistics you choose will be calculated for each unique value of Crime_type.

## Parameters

`arcpy.analysis.SummarizeWithin(in_polygons, in_sum_features, out_feature_class, {keep_all_polygons}, {sum_fields}, {sum_shape}, {shape_unit}, {group_field}, {add_min_maj}, {add_group_percent}, {out_group_table})`

### Code sample

SummarizeWithin example 1 (Python window)

The following Python window script demonstrates how to use the SummarizeWithin function.

``````import arcpy
arcpy.env.workspace = 'C:/data/city.gdb'
arcpy.analysis.SummarizeWithin('neighborhoods', 'crimes', 'neighborhood_crimes')``````
SummarizeWithin example 2 (stand-alone script)

The following standalone script is an example of how to use the SummarizeWithin function in a scripting environment.

``````# Description: Use SummarizeWithin to summarize the crimes in each city neighborhood

# import system modules
import arcpy

# Set environment settings
arcpy.env.workspace = 'C:/data/city.gdb'

#  Set local variables
polys = 'neighborhoods'
points = 'crimes'
outFeatureClass = 'crimes_aggregated'
keepAll = 'KEEP_ALL'
sumFields = [['Damages', 'SUM'], ['VICTIM_AGE', 'MEAN']]
groupField = 'Crime_type'
outTable = 'crimes_aggregated_groups'

arcpy.analysis.SummarizeWithin(polys, points, outFeatureClass, keepAll,