HOW TO

Rank polygons by density using Arcade in ArcGIS Enterprise portal and ArcGIS Online

Last Published: July 17, 2024

Summary

In the ArcGIS Enterprise portal and ArcGIS Online, polygon features can be ranked based on the density of field values within each polygon. This is calculated by dividing the value of a specified field in a polygon by the polygon's area. An ArcGIS Arcade script can be used to compare the density of field values across all polygons in a layer and assign a rank to each polygon based on this comparison. This is ideal for visualization analysis, as creating a rank-based visualization allows for quick identification of areas with significant concentrations of points. This can aid in decision-making processes by highlighting areas that need attention or further investigation.

This article describes the workflow to rank polygons by density using an Arcade expression in Portal for ArcGIS and ArcGIS Online.

Procedure

  1. Log in to the ArcGIS Enterprise portal or ArcGIS Online and click Content > My Content.
  2. Click the hosted feature layer containing the polygons to open the item details page.
  3. Calculate the field to rank the polygons using Arcade. In this example, the Rank field is selected. Refer to Portal for ArcGIS: Calculate values for a field or ArcGIS Online: Calculate values for a field from the item page for instructions.
The Rank field is selected in the attribute table
  1. In the Expression box, specify the following Arcade expression:
    1. Define the expression to calculate the rank. Replace <fieldName> with the name of the desired field to be ranked.
var rankExpression = $feature["<fieldName>"] / $feature["SHAPE__Area"];
  1. Use the FeatureSetByName function to retrieve all features. Replace <polygonName> with the name of the polygon layer.
var allFeatures = FeatureSetByName($datastore, "<polygonName>");
  1. Initialize variables for tracking ranks.
var currentRank = 1;
var currentFeatureRank = 1;
  1. Iterate through all features to calculate ranks.
for (var feature in allFeatures) {
    if (feature == $feature) {
        continue;
    }

    var featureRank = feature["<fieldName>"] / feature["SHAPE__Area"];
    if (featureRank > rankExpression) {
        currentRank++;
    }
}
  1. Return the rank of the current feature.
return currentRank;

The code block below shows the example of the full working script.

var rankExpression = $feature["numberofpoints"] / $feature["SHAPE__Area"];

var allFeatures = FeatureSetByName($datastore, "Polygon");

var currentRank = 1;
var currentFeatureRank = 1;

for (var feature in allFeatures) {
    if (feature == $feature) {
        continue;
    }

    var featureRank = feature["numberofpoints"] / feature["SHAPE__Area"];
    if (featureRank > rankExpression) {
        currentRank++;
    }
}

return currentRank;
  1. Click OK.

The image below shows the polygons are ranked based on the density of the field values in the attribute table. The rank of each polygon is determined by counting the higher ratio. The more features with a higher ratio, the lower the number value in the Rank field.

The polygons are ranked in the attribute table

Article ID: 000033017

Software:
  • ArcGIS Online
  • Portal for ArcGIS
  • ArcGIS Enterprise 11 1
  • ArcGIS Enterprise 11 3
  • ArcGIS Enterprise 11 2

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options