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

The following are example scenarios using Summarize Within:

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

## Illustration ## 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, you can look down through the stack and count the number of input summary features that fall within the input polygons. You can also 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. Using the Summarize Within tool, you can summarize features within existing polygons. Using 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 crime types. Each unique crime type forms a group, and the statistics you choose will be calculated for each unique Crime_type value.

• Null values are excluded from all statistical calculations. For example, the average of 10, 5, and a null value is 7.5 ((10+5)/2).

## 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 stand-alone 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,