HOW TO

Calculate coordinates of polygon features using Arcade in ArcGIS Pro

Last Published: July 18, 2024

Summary

In ArcGIS Pro, the calculation of polygon feature coordinates can enhance spatial query accuracy, facilitate geospatial computations, and support advanced mapping and visualization tasks. However, since the coordinates of a polygon feature, which has an area, are indefinite, the coordinates of a polygon feature are represented by the centroids of the polygons. Centroids are point features that represent the center of the polygon features.

This article details the workflow to calculate the coordinates of polygon features based on their centroids using an ArcGIS Arcade expression in ArcGIS Pro.

Procedure

  1. Open the ArcGIS Pro project.
  2. In the Contents pane, right-click the feature layer and click Attribute Table.
  3. Create a new text field type to store the coordinates. In this example, the new field is named Coordinate.
  4. In the attribute table, right-click the field name, and select Calculate Field.
  5. In the Calculate Field window, specify the following parameters:
    1. For Input Table, ensure the layer from Step 2 is selected. In this example, the Test layer is used.
    2. For Field Name, ensure the field created in Step 3 is selected.
    3. For Expression Type, select Arcade.
    4. For Expression, in the expression box, specify the expression provided below.
//return the geometry of the feature
var poly = Geometry($feature);

var result = "";
//return the centroid of the polygon feature
if (!IsEmpty(poly)) {
    var pnt_centr = Centroid(poly);
    Console(pnt_centr);    
    result = "(" + Round(pnt_centr.X, 2) + ", " + Round(pnt_centr.Y, 2) + ")";
}
//return the result
return result
  1. Click the Verify icon to validate the expression.
  2. Click OK to run the script.
The Arcade expression configuration in the Calculate Field dialog box

The image below displays the Coordinate field populated with the coordinates of the polygons based on the map's coordinate system in the attribute table.

The coordinates of the polygon features using the map's coordinate system as units in the attribute table

Alternatively, specify the following Arcade expression in the expression box to calculate the coordinates in decimal degrees.

function MetersToLatLon(mx, my) {
    var originShift = 2.0 * PI * 6378137.0 / 2.0;
    var lon = (mx / originShift) * 180.0;
    var lat = (my / originShift) * 180.0;

    lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
    return [lat, lon];
}
var poly = Geometry($feature);
var result = "";
if (!IsEmpty(poly)) {
    var pnt_centr = Centroid(poly);
    var latlon = MetersToLatLon(pnt_centr.x, pnt_centr.y);
    result = "(" + Round(latlon[0], 6) + ", " + Round(latlon[1], 6) + ")";
} else {
    result = "";
}
return result

The image below displays the Coordinate field populated with the coordinates of the polygons in decimal degrees in the attribute table.

The coordinates of the polygon features using decimal as units in the attribute table

Article ID: 000033014

Software:
  • ArcGIS Pro 3 1
  • ArcGIS Pro 3 3
  • ArcGIS Pro 3 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