HOW TO

Unlike a point feature, the coordinates of a polygon feature, which has an area, are indefinite. Therefore, to determine the coordinates of a polygon feature, the centroids of the polygons are calculated. Centroids are point features that represent the center of the polygon features.

This article describes the workflow to calculate the coordinate of polygon features based on its centroids using an Arcade expression in ArcGIS Online.

- Log in to ArcGIS Online. Click
**Content**>**My Content**. - Ensure the attribute table of the polygon features is editable. Publish the feature layer as a hosted feature layer and enable the editing capabilities.
- On the item details page of the polygon feature layer, click the
**Data**tab to display the table.

- Add a new string data type field. Refer to ArcGIS Online: Add a field for instructions. In this example, the new Coordinate field is created.

- Populate the new field using the Arcade expression.
- Click the
**Coordinate**field and select**Calculate**from the field options.

- Click the

- In the
**Calculate Field: Coordinate**window, select**Arcade**. - In the
**Arcade Calculator: Coordinate**window, in the**Expression**box, enter the following Arcade expression:

//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

- Click
**OK**.

The Coordinate field is populated with coordinates of the polygon features' centroids. The unit of the coordinates follows the map's coordinate system.

Alternatively, to calculate the coordinates in decimal degrees, use the following Arcade expressions in the **Expression **box:

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 Lat_Long field is populated with coordinates of the polygon features' centroids in decimal degrees.

Get help from ArcGIS experts

Download the Esri Support App