Summary
In ArcGIS Pro, it is possible to automatically calculate polygon feature centroids and the coordinates when the polygon features are added or updated on the map. This functionality can be automated using attribute rules to ensure the centroids of the polygon features are consistently and accurately maintained, reducing manual calculations and minimizing the risk of errors.
This article provides the workflow to automatically calculate the centroids of polygon features using attribute rules.
Procedure
Note:
An ArcGIS Pro Standard license or higher is required to create and manage attribute rules.
- Open the project in ArcGIS Pro.
Note:
The feature layer requires Global IDs to add an attribute rule.
- Add a Global ID field to the attribute table of the polygon feature layer using the Add Global IDs tool.
- Create two new fields with the double data type to store the centroid X and Y coordinates. Refer to ArcGIS Pro: Create a field and apply a domain and default value for instructions. In this example, the X coordinate field is named Centroid_X, and the Y coordinate field is named Centroid_Y.
- In the Contents pane, right-click the polygon feature layer and click Data Design > Attribute Rules.
- In the Attribute Rules view, add attribute rules to the X and Y coordinate fields.
- On the Calculation tab, click the Add Rule drop-down menu and select Immediate Calculation.
- In the New Rule pane, specify a name for Rule Name. In this example, the rule is named 'Calculate the centroid X coordinate'.
- For Field, select the X coordinate field from the drop-down menu. In this example, Centroid_X is selected.
- In the Expression box, specify the following Arcade expression:
Centroid($feature).x
- Under Triggers, check the Insert and Update check boxes.
- Repeat Steps 5(a) through 5(e) to add a new rule for the Y coordinate field in the Attribute Rule view using the following Arcade expression:
Centroid($feature).y
- On the Attribute Rules tab, in the Manage Edits group, click Save.
The following image shows the X and Y coordinates of the centroids are automatically calculated when new polygon features are added to the map.