HOW TO

Calculate coordinates of polygon features using Arcade in ArcGIS Online

Last Published: January 16, 2024

Summary

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.

Procedure

  1. Log in to ArcGIS Online. Click Content > My Content.
  2. Ensure the attribute table of the polygon features is editable. Publish the feature layer as a hosted feature layer and enable the editing capabilities.
  3. On the item details page of the polygon feature layer, click the Data tab to display the table.
The Data tab on the item details page in ArcGIS Online.
  1. 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.
The Coordinate field is added to the table.
  1. Populate the new field using the Arcade expression.
    1. Click the Coordinate field and select Calculate from the field options.
The Calculate option from the Coordinate field options.
  1. In the Calculate Field: Coordinate window, select Arcade.
  2. 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
  1. Click OK.
The Arcade Calculator window with the Arcade expression.

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

The Coordinate field is populated with the coordinates of the centroids.

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.

The coordinates in decimal degrees populate the Lat_Long field.

Article ID: 000028324

Software:
  • ArcGIS Online

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