Summary
In ArcGIS Pro, attribute rules can automatically calculate the sum of attribute values from intersecting features based on matching attribute values. This eliminates the need to manually calculate and enter the values when working with features that intersect and share related attributes.
In this article, an attribute rule automatically calculates the HomeCount field in the polygon feature class by summing values from intersecting point features of which the Identifier field matches the polygon's Designation field. The map below shows an example of the features used in this workflow.
Procedure
- Open the ArcGIS Pro project.
- In the Catalog pane, browse to and right-click the feature class and click Manage. In this example, the polygon feature class, LocationIdentifier_1, is selected.
- In the Feature Class Properties window, in the Manage section, check the Global IDs check box and click OK.
- Right-click the feature layer in the Contents pane and click Data Design > Attribute Rules. In this example, the LocationIdentifier_1 is selected.
- Click the Add Rule drop-down list and select Immediate Calculation.
- Specify the Rule Name. In this example, Count Home is used.
- For Field, select the field to use. In this example, HomeCount is used.
- Add the following Arcade expression in the Expression box.
- Define <variable_name1> with a name to label the matching field value. Replace <PolygonMatchField> with the matching field name. In this example, <variable_name1> is defined as polyStatus, and the Designation field is used to match both features.
var <variable_name1>= Text($feature.<PolygonMatchField>);
- Specify a condition to check whether <variable_name1> is empty. If it is empty, return 0. In this example, <variable_name1> is replaced with polyStatus.
if (IsEmpty(<variable_name1>)) {
return 0;
}
- Define <variable_name2> as the point feature specified in <PointFeatureClass>. Specify <PointMatchField> and <ValueField> as the fields to retrieve. In this example, <variable_name2> is defined as pts, <PointFeatureClass> is Address_1, and the Identifier and HomeCount fields are retrieved.
var <variable_name2> = FeatureSetByName($datastore, <"PointFeatureClass">, [<"PointMatchField">, <"ValueField">], true);
- Define <variable_name3> by filtering <variable_name2> using <PointMatchField> to match <variable_name1>. In this example, <variable_name3> is defined as statusFiltered.
var <variable_name3> = Filter(<variable_name2>, <"PointMatchField = '"> + <variable_name1> + "'");
- Define <variable_name4> with the features that intersect the current feature. In this example, <variable_name4> is defined as intersecting.
var <variable_name4> = Intersects(<variable_name3>, Geometry($feature));
- Define <variable_name5> with an initial value of 0 to store the total. In this example, <variable_name5> is defined as totalSum.
var <variable_name5> = 0;
- Specify a for loop to iterate through each feature in <variable_name4>. If <ValueField> is not empty, add its numeric value to <variable_name5> and return <variable_name5> as the total value. Replace <ValueField> with the field containing the values to sum. In this example, <ValueField> is HomeCount.
for (var p in <variable_name4>) {
if (!IsEmpty(p[<"ValueField">])) {
<variable_name5> += Number(p[<"ValueField">]);
}
}
return <variable_name5>;
Below is the full working code of the Arcade expression.
var polyStatus = Text($feature.Designation);
if (IsEmpty(polyStatus)) {
return 0;
}
var pts = FeatureSetByName($datastore, "Address", ["Identifier", "HomeCount"], true);
var statusFiltered = Filter(pts, "Identifier = '" + polyStatus + "'");
var intersecting = Intersects(statusFiltered, Geometry($feature));
var totalSum = 0;
for (var p in intersecting) {
if (!IsEmpty(p["HomeCount"])) {
totalSum += Number(p["HomeCount"]);
}
}
return totalSum;
- Under Triggers, check the Insert and Update check box.
- On the Attribute Rules tab, in the Manage Edits group, click Save.
The attribute table below shows the polygon's HomeCount field populated automatically with the sum of intersecting point values when the Designation field is updated.