Learn how to aggregate and summarize features from feature data.
A summarize analysis finds which features in a layer are near or within features in another layer. It also calculates statistics such as the number of features that are in or near another layer.
In this tutorial, you use the Aggregate Points and Summarize Center and Dispersion operations to find the areas with the most incident reports about graffiti in San Francisco. You can perform the combine analyses either in Map Viewer or programmatically using the ArcGIS Python, ArcGIS REST JS, and ArcGIS REST APIs.
The analyses include:
- Counting the number of calls concerning graffiti by census blocks.
- Finding the median centers for incidents grouped by reported offensive and non-offensive graffiti.
Prerequisites
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.
-
Go to the Summarize data tutorial web map and click Sign in.
-
Verify that you have the following layers by toggling the visibility on and off:
- Graffiti cases within San Francisco
- Census blocks in three neighborhoods
-
Click Save and open > Save As to save a copy.
Count reported incidents of graffiti within census blocks
The Census blocks in three neighborhoods SF hosted feature layer displays the census blocks for the Inner Mission, Hayes Valley, and South of Market neighborhoods. The Graffiti cases within SF hosted layer contains approximately 5,700 features representing reports on various incidents of graffiti within the area. Use the Aggregate Points operation to find the census blocks with the highest count of reported incidents of graffiti.
-
In the Settings (light) toolbar, click Analysis > Tools > Aggregate Points.
-
Set the following parameters:
- Input features: Graffiti cases within San Francisco
- Area type: Polygon layer
- Summary polygon layer: Census blocks in three neighborhoods SF.
- Uncheck Keep areas with no points.
- Output name:
Graffiti incidents within census blocks
.
-
Click Estimate credits. The estimated cost for ArcGIS Location Platform is USD $0.628 and ArcGIS Online is 6.285 credits.
-
Click Run.
-
Click on the census blocks to view the Count of Points attribute in the popup.
Style the census blocks
You can change the renderer style to make it easier to visualize which census blocks have the highest number of reported incidents.
-
Select the Graffiti incidents within census blocks layer.
-
In the Settings (light) toolbar, click Styles.
-
In Counts and Amounts (Color), click Style options.
-
Click Symbol style to select a blue to purple color ramp. Click Done, then close the Symbol style window.
-
Check Classify Data. Select Natural breaks.
-
Click Done twice to close the Styles pane.
-
Implement authentication with the following privileges:
- Spatial Analysis > Feature Analysis
-
Define the parameters.
-
Perform the operation.
Note: This is a long transaction managed with a job request.
-
Handle the results.
APIs
from arcgis import GIS
from arcgis.features.analysis import aggregate_points
portal = GIS(username="<USERNAME>", password="<PASSWORD>")
census_blocks = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Census_blocks_in_three_neighborhoods_SF/FeatureServer/0"
graffiti = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Graffiti_cases_within_census_blocks/FeatureServer/0"
results = aggregate_points(
polygon_layer=census_blocks,
point_layer=graffiti,
keep_boundaries_with_no_points=False,
)
result_features = results["aggregated_layer"].query()
print(
f"aggregate points result layer contains {len(result_features.features)} new records"
)
# show results in notebook with the map widget
map_widget = portal.map()
map_widget.add_layer(result_features)
map_widget.zoom_to_layer(result_features)
map_widget
Service requests
Request
POST arcgis.com/sharing/rest/portals/self HTTP/1.1
Content-Type: application/x-www-form-urlencoded
&f=json
&token=<ACCESS_TOKEN>
Response (JSON)
{
"helperServices": {
// Other parameters
"analysis": {
"url": "https://<YOUR_ANALYSIS_SERVICE>/arcgis/rest/services/tasks/GPServer"
},
"geoenrichment": {
"url": "https://geoenrich.arcgis.com/arcgis/rest/services/World/GeoenrichmentServer"
}
}
}
Style the layer
To learn how to style a feature layer, go to Visualization.
{
"renderer": {
"authoringInfo": {
"type": "classedColor",
"classificationMethod": "esriClassifyNaturalBreaks"
},
"type": "classBreaks",
"field": "Point_Count",
"minValue": 1,
"classBreakInfos": [
The aggregated incidents within census blocks should look something like this.
Find the median centers of graffiti reports by type
The Graffiti cases within San Francisco layer is styled based on report type. To find the median center and ellipses of reports based on their type, use the Summarize Center and Dispersion operation. You use the median center and ellipses of reports because the data is not distributed evenly. Ellipses summarize the central tendency, dispersion, and directional trends of data sized for one standard deviation and will help contextualize the median centers.
-
In the Settings (light) toolbar, click Analysis > Tools > Summarize Center and Dispersion.
-
Set the following parameters:
- Input layer: Graffiti cases within San Francisco.
- Summary types: Select Median Center and Ellipse. Keep 1 standard deviation for the Ellipse size.
- Group by field: Offensive/NotOffensive
- Output name:
Median centers of incidents by type
.
-
Click Estimate credits. The estimated cost for ArcGIS Location Platform is USD $0.57 and ArcGIS Online is 5.711 credits.
-
Click Run.
-
Click on the resulting features and view the popup.
Style median centers
You can change the renderer style to make it easier to visualize the dispersion and center for the types of reports.
- Select the MedianCenterLayer from Median centers of incidents by type group layer.
- In the Settings (light) toolbar, select Styles.
- Click + Field and select the Offence field.
- Click Style options, and choose red for Offensive, orange for Non-Offensive an gray for Other.
- Click Done twice to close the style pane.
Style ellipses
- Select the EllipseLayer from Median centers of incidents by type group layer.
- In the Settings (light) toolbar, select Styles.
- Click + Field and select the Offensive/NotOffensive field.
- Under Types (unique symbols), select Style options.
- Set the Fill Color to No Color for each type.
- Set the Outline color for each type to match the color scheme you choose for the median centers above.
- Click Done twice to close the style pane.
- In the Contents (dark) toolbar, click Save and open > Save to save your work.
-
Implement authentication with the following privileges:
- Spatial Analysis > Feature Analysis
-
Define the parameters.
-
Perform the operation.
Note: This is a long transaction managed with a job request.
-
Handle the results.
APIs
from arcgis import GIS
from arcgis.features.analysis import summarize_center_and_dispersion
portal = GIS(username="<USERNAME>", password="<PASSWORD>")
graffiti = {
"url": "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Graffiti_cases_within_census_blocks/FeatureServer/0",
}
results = summarize_center_and_dispersion(
analysis_layer=graffiti,
summarize_type=["MedianCenter", "Ellipse"],
ellipse_size="1 standard deviation",
)
result_features = results["ellipse_result_layer"].query()
print(
f"summarize result layer contains {len(result_features.features)} records"
)
# show results in notebook with the map widget
map_widget = portal.map()
map_widget.add_layer(result_features)
map_widget.zoom_to_layer(result_features)
map_widget
Service requests
Request
POST arcgis.com/sharing/rest/portals/self HTTP/1.1
Content-Type: application/x-www-form-urlencoded
&f=json
&token=<ACCESS_TOKEN>
Response (JSON)
{
"helperServices": {
// Other parameters
"analysis": {
"url": "https://<YOUR_ANALYSIS_SERVICE>/arcgis/rest/services/tasks/GPServer"
},
"geoenrichment": {
"url": "https://geoenrich.arcgis.com/arcgis/rest/services/World/GeoenrichmentServer"
}
}
}
Style the layer
To learn how to style a feature layer, go to Visualization.
//Median
{
"renderer": {
"type": "uniqueValue",
"field1": "Offence",
"uniqueValueInfos": [
{
"value": "Not offensive",
"symbol": {
"color": [
The values of these features represent the median centers of the type of graffiti: offensive, non-offensive, or other. You should also see the ellipses that summarize the dispersion within one standard deviation for each category.
What's next?
You performed two types of summarize analyses. You aggregated points within census blocks and found the median centers of reported incidents categorized by the type of graffiti. Your web map should look something like this.
Learn how to use additional tools, APIs, and location services in these tutorials:
Find and extract data
Find data with attribute and spatial queries using find analysis operations.
Discover patterns in data
Find patterns and trends in data using spatial analysis operations.
Combine data
Overlay, join, and dissolve features using combine analysis operations.