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/GPServer/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 reutrn 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 OAuth 2.0 access token. Learn how to get an access token in Security and authentication. | token=< |
input | The point or polyline features from the feature dataset. | {"url":"https: |
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":"https: |
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":{"xmin: |
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://services.arcgis.com/nSZVuSZjHpEZZbRo/arcgis/rest/services/OSM_POI/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"
}
}
}
Request
POST <YOUR_ANALYSIS_SERVICE>/arcgis/rest/services/tasks/GPServer/CalculateDensity/submitJob HTTP/1.1
Content-Type: application/x-www-form-urlencoded
&f=json
&token=<ACCESS_TOKEN>
&inputLayer={"url":"https://services.arcgis.com/nSZVuSZjHpEZZbRo/arcgis/rest/services/OSM_POI/FeatureServer/0","name":"OpenStreetMap - Points of interest (bèta) - Punten"}
&areaUnits=SquareMiles
&boundingPolygonLayer={"url":"https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Nijmegen_boundary_layer/FeatureServer/3"}
&numClasses=10
&outputName={"serviceProperties":{"name":"Calculate density results"}}
&context={}
&returnFeatureCollection=false
Response (JSON)
{
"jobId": "<JOB_ID>",
"jobStatus": "esriJobSubmitted",
"results": {},
"inputs": {},
"messages": []
}
Request
POST <YOUR_ANALYSIS_SERVICE>/arcgis/rest/services/tasks/GPServer/CalculateDensity/jobs/<JOB_ID> HTTP/1.1
Content-Type: application/x-www-form-urlencoded
&f=json
&token=<ACCESS_TOKEN>
Response (JSON)
// Executing job
{
"jobId": "<JOB_ID>",
"jobStatus": "esriJobExecuting",
"results": {},
"inputs": {},
"messages": []
}
// Job succeeded
{
"jobId": "<JOB_ID>",
"jobStatus": "esriJobSucceeded",
"results": {
"resultLayer": {
"paramUrl": "results/resultLayer"
},
},
"inputs": {},
"messages": []
}
Request
POST <YOUR_ANALYSIS_SERVICE>/arcgis/rest/services/tasks/GPServer/CalculateDensity/jobs/<JOB_ID>/results/resultLayer HTTP/1.1
Content-Type: application/x-www-form-urlencoded
&f=json
&returnType=data
&token=<ACCESS_TOKEN>
Response (JSON)
{
"paramName": "resultLayer",
"dataType": "GPString",
"value": {
"url": "<SERVICE_URL>",
"itemId": "<ITEM_ID>"
}
}
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"
}
}
}
Request
POST <YOUR_ANALYSIS_SERVICE>/arcgis/rest/services/tasks/GPServer/CalculateDensity/submitJob HTTP/1.1
Content-Type: application/x-www-form-urlencoded
&f=json
&inputLayer={"url":"https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Portland Bike Routes/FeatureServer/0","name":"Portland Bike Routes"}
&areaUnits= SquareMiles
&boundingPolygonLayer={"url":"https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Portland_boundary/FeatureServer/0","name":"Portland_boundary-DissolvedFeatures"}
&classificationType= EqualInterval
&numClasses=10
&outputName={"serviceProperties":{"name":"Calculate density results"}}
&returnFeatureCollection=false
&token=<ACCESS_TOKEN>
Response (JSON)
{
"jobId": "<JOB_ID>",
"jobStatus": "esriJobSubmitted",
"results": {},
"inputs": {},
"messages": []
}
Request
POST <YOUR_ANALYSIS_SERVICE>/arcgis/rest/services/tasks/GPServer/CalculateDensity/jobs/<JOB_ID> HTTP/1.1
Content-Type: application/x-www-form-urlencoded
&f=json
&token=<ACCESS_TOKEN>
Response (JSON)
// Executing job
{
"jobId": "<JOB_ID>",
"jobStatus": "esriJobExecuting",
"results": {},
"inputs": {},
"messages": []
}
// Job succeeded
{
"jobId": "<JOB_ID>",
"jobStatus": "esriJobSucceeded",
"results": {
"resultLayer": {
"paramUrl": "results/resultLayer"
},
},
"inputs": {},
"messages": []
}
Request
POST <YOUR_ANALYSIS_SERVICE>/arcgis/rest/services/tasks/GPServer/CalculateDensity/jobs/<JOB_ID>/results/resultLayer HTTP/1.1
Content-Type: application/x-www-form-urlencoded
&f=json
&returnType=data
&token=<ACCESS_TOKEN>
Response (JSON)
{
"paramName": "resultLayer",
"dataType": "GPString",
"value": {
"url": "<SERVICE_URL>",
"itemId": "<ITEM_ID>"
}
}
Tutorials
Learn how to perform related analyses interactively with Map Viewer and programmatically with ArcGIS API for Python, ArcGIS REST JS, and ArcGIS REST API.
Services
Spatial analysis service
Process spatial datasets to discover relationships and patterns.
API support
Find hot spots | Find outliers | Find point clusters | Calculate density | Interpolate points | |
---|---|---|---|---|---|
ArcGIS Maps SDK for JavaScript | 1 | 1 | 1 | 1 | 1 |
ArcGIS Maps SDK for .NET | |||||
ArcGIS Maps SDK for Kotlin | |||||
ArcGIS Maps SDK for Swift | |||||
ArcGIS Maps SDK for Java | |||||
ArcGIS Maps SDK for Qt | |||||
ArcGIS API for Python | |||||
ArcGIS REST JS | 1 | 1 | 1 | 1 | 1 |
Esri Leaflet | 2 | 2 | 2 | 2 | 2 |
MapBox GL JS | 2 | 2 | 2 | 2 | 2 |
OpenLayers | 2 | 2 | 2 | 2 | 2 |
- 1. Access with geoprocessing task
- 2. Access via ArcGIS REST JS