A density analysis resulting in a new layer with traffic crashes per square mile in San Francisco.
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 Density
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. The general steps to calculating density are as follows:
Review the parameters for the Calculate Density
operation. 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 Layer
: Your dataset as a hosted feature layer or feature collection.area Units
: Such as square miles. classification Type
: Equal interval, natural breaks etc.output Name
: A string representing the name of the hosted feature layer to reutrn with the results. 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
Use dark colors for code blocks Copy
1
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=< ACCESS_ TOKEN>
input Layer
The point or polyline features from the feature dataset . {"url":"https: //services.arcgis.com/n SZVu S Z j Hp EZZb Ro/arcgis/rest/services/OSM_ POI/Feature Server/0","name":"Open Street Map - Points of interest (bèta) - Punten"}
Key parameters Name Description Examples area Units
The units of the calculated density values. Square Miles
, Square Kilometers
bounding Polygon Layer
The polygon(s) from a hosted feature layer or feature collection in which you want densities to be calculated. {"url":"https: //services3.arcgis.com/GVgb Jbqm8h XASVYi/arcgis/rest/services/Portland_ boundary/Feature Server/0"}
classification Type
How density values will be classified. Natural Breaks
num Classes
Number used to divide the range of predicted values into distinct classes. 10
output Name
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 Properties": {"name": "< SERVICE_ NAME>"}}
context
A bounding box or output spatial reference for the analysis. "extent":{"xmin: ", "ymin: ", "xmax: ", "ymax: "}
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 Layer
value is the OpenStreetMap - Points of interest (bèta) hosted feature layer. The density values are calculated by Natural Breaks
with 10
classes within a bounding Polygon Layer
.
Calculate density analysis showing the density of points of interest in Nijmegen.
APIs ArcGIS API for Python ArcGIS API for Python ArcGIS REST JS
Expand
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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 1. Get the analysis service URL 2. Submit job 3. Check job status 4. Get results
Request HTTP HTTP cURL
Use dark colors for code blocks Copy
1
2
3
4
5
POST arcgis.com/sharing/rest/portals/self HTTP/1.1
Content-Type : application/x-www-form-urlencoded
&f=json
&token= < ACCESS_TOKEN >
Response (JSON)
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
{
"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 HTTP HTTP cURL
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{
"jobId" : "<JOB_ID>" ,
"jobStatus" : "esriJobSubmitted" ,
"results" : {},
"inputs" : {},
"messages" : []
}
Request HTTP HTTP cURL
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// 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 HTTP HTTP cURL
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{
"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 Layer
value is the Bike routes hosted feature layer. The density values are calculated by Natural Breaks
with 10
classes within a bounding Polygon Layer
.
Calculate density analysis showing the density of bike routes per square mile in a section of Portland.
APIs ArcGIS API for Python ArcGIS API for Python ArcGIS REST JS
Expand
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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 1. Get the analysis service URL 2. Submit job 3. Check job status 4. Get results
Request HTTP HTTP cURL
Use dark colors for code blocks Copy
1
2
3
4
5
POST arcgis.com/sharing/rest/portals/self HTTP/1.1
Content-Type : application/x-www-form-urlencoded
&f=json
&token= < ACCESS_TOKEN >
Response (JSON)
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
{
"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 HTTP HTTP cURL
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{
"jobId" : "<JOB_ID>" ,
"jobStatus" : "esriJobSubmitted" ,
"results" : {},
"inputs" : {},
"messages" : []
}
Request HTTP HTTP cURL
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// 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 HTTP HTTP cURL
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{
"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 Process spatial datasets to discover relationships and patterns.
API support Full support Partial support No support