What is a density analysis?
A density analysis is the process of spreading out known quantities of point attributes and classifying the areas on a scale of least to most dense per square mile or per square kilometer. To execute the analysis, use the spatial analysis service and the Calculate
operation.
Real-world examples of this analysis include the following:
- Visualizing population density.
- Finding the density of points of interest (POI) for site selection.
- Visualizing the density of crimes within a city.
- Finding the areas with more forest fires and other natural disasters.
How to perform a calculate density analysis
The general steps to calculating density are as follows:
- Review the parameters for the
Calculate
operation.Density - Send a request to get the spatial analysis service URL.
- Execute a job request with the following URL and parameters:
- URL:
https
:// <YOUR _ANALYSIS _SERVICE >/arcgis/rest/services/tasks/ GP Server/ Calculate Density/submit Job - Parameters:
input
: Your dataset as a hosted feature layer or feature collection.Layer area
: Such as square miles.Units classification
: Equal interval, natural breaks etc.Type output
: A string representing the name of the hosted feature layer to return with the results.Name
- URL:
- Check the status.
- Get the output layer results.
To see examples using ArcGIS API for Python, ArcGIS REST JS, and the ArcGIS REST API, go to Examples below.
URL request
https://analysis3.arcgis.com/arcgis/rest/services/tasks/GPServer/CalculateDensity/submitJob?<parameters>
Required parameters
Name | Description | Examples |
---|---|---|
f | The format of the data returned. | f=json f=pjson |
token |
An access token (API key or OAuth 2.0) with the required Spatial Analysis > Feature analysis privilege. with the following privileges:
| token= |
input | The point or polyline features from the feature dataset. | {"url" |
Key parameters
Name | Description | Examples |
---|---|---|
area | The units of the calculated density values. | Square , Square |
bounding | The polygon(s) from a hosted feature layer or feature collection in which you want densities to be calculated. | {"url" |
classification | How density values will be classified. | Natural |
num | Number used to divide the range of predicted values into distinct classes. | 10 |
output | A string representing the name of the hosted feature layer to return with the results. NOTE: If you do not include this parameter, the results are returned as a feature collection (JSON). | {"service |
context | A bounding box or output spatial reference for the analysis. | "extent" |
Example
Calculate the density of POI
This example finds where there are the most POIs per square mile in the area surrounding Nijmegen. The input
value is the OpenStreetMap - Points of interest (bèta) hosted feature layer. The density values are calculated by Natural
with 10
classes within a bounding
.
APIs
osm_poi = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/OpenStreetMap - Points of interest/FeatureServer/0"
boundary = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Nijmegen_boundary_layer/FeatureServer/3"
results = calculate_density(
input_layer=osm_poi,
bounding_polygon_layer=boundary,
context={
"extent": {
"xmin": 636264.364494962,
"ymin": 6760768.706403579,
"xmax": 669246.9421999712,
"ymax": 6781311.157755191,
"spatialReference": {"wkid": 102100, "latestWkid": 3857},
},
"outSR": {"wkid": 3857},
},
# Outputs results as a hosted feature layer.
output_name="Calculate density results",
)
result_features = results.layers[0].query()
print(f"The density layer has {len(result_features.features)} new records")
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"
}
}
}
Calculate the density of bike routes
This example finds where there are the most bike routes per square mile within the boundary of Portland. The input
value is the Bike routes hosted feature layer. The density values are calculated by Natural
with 10
classes within a bounding
.
APIs
bike_routes = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Portland Bike Routes/FeatureServer/0"
boundary = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Portland_boundary/FeatureServer/0"
results = calculate_density(
input_layer=bike_routes,
bounding_polygon_layer=boundary,
classification_type="GeometricInterval",
area_units="SquareMiles",
# Outputs results as a hosted feature layer.
output_name="Calculate density results",
)
result_features = results.layers[0].query()
print(f"The density layer has {len(result_features.features)} new records")
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"
}
}
}