Calculate density

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 CalculateDensity operation.

calculate density

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:

  1. Review the parameters for the CalculateDensity operation.
  2. Send a request to get the spatial analysis service URL.
  3. Execute a job request with the following URL and parameters:
    • URL: https://<YOUR_ANALYSIS_SERVICE>/arcgis/rest/services/tasks/GPServer/CalculateDensity/submitJob
    • Parameters:
      • inputLayer: Your dataset as a hosted feature layer or feature collection.
      • areaUnits: Such as square miles.
      • classificationType: Equal interval, natural breaks etc.
      • outputName: A string representing the name of the hosted feature layer to return with the results.
  4. Check the status.
  5. 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 blocksCopy
1
https://analysis3.arcgis.com/arcgis/rest/services/tasks/GPServer/CalculateDensity/submitJob?<parameters>

Required parameters

NameDescriptionExamples
fThe 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:
  • portal:user:createItem
  • portal:publisher:publishFeatures
  • premium:user:spatialanalysis
token=<ACCESS_TOKEN>
inputLayerThe point or polyline features from the feature dataset.{"url":"https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/OpenStreetMap - Points of interest/FeatureServer/0","name":"OpenStreetMap - Points of interest (bèta) - Punten"}

Key parameters

NameDescriptionExamples
areaUnitsThe units of the calculated density values.SquareMiles, SquareKilometers
boundingPolygonLayerThe polygon(s) from a hosted feature layer or feature collection in which you want densities to be calculated.{"url":"https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Portland_boundary/FeatureServer/0"}
classificationTypeHow density values will be classified.NaturalBreaks
numClassesNumber used to divide the range of predicted values into distinct classes.10
outputNameA 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).{"serviceProperties": {"name": "<SERVICE_NAME>"}}
contextA 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 inputLayer value is the OpenStreetMap - Points of interest (bèta) hosted feature layer. The density values are calculated by NaturalBreaks with 10 classes within a boundingPolygonLayer.

Calculate density analysis showing the density of points of interest in Nijmegen.

APIs

ArcGIS API for PythonArcGIS API for PythonArcGIS REST JS
Expand
Use dark colors for code blocksCopy
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://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
HTTPHTTPcURL
Use dark colors for code blocksCopy
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 blocksCopy
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"
    }
  }
}

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 inputLayer value is the Bike routes hosted feature layer. The density values are calculated by NaturalBreaks with 10 classes within a boundingPolygonLayer.

Calculate density analysis showing the density of bike routes per square mile in a section of Portland.

APIs

ArcGIS API for PythonArcGIS API for PythonArcGIS REST JS
Expand
Use dark colors for code blocksCopy
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

Request
HTTPHTTPcURL
Use dark colors for code blocksCopy
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 blocksCopy
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"
    }
  }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.