HOW TO

Calculate XY values using Arcade in ArcGIS Pro

Last Published: June 20, 2023

Summary

In ArcGIS Pro, spatial and location information of point features can be added to the attribute table and this task can be automated using Arcade. The workflow provided in this article describes how to calculate the XY values of point features using an Arcade expression.

Procedure

  1. Open the ArcGIS Pro project.
  2. Add a new field to the feature class in ArcGIS Pro for the x-value.
    1. In the Contents pane, right-click the layer and click Attribute Table.
    2. In the attribute table, click Add Field The Add Field icon..
    3. In the Fields view, specify a name for the field in the Field Name column.
    4. Double-click the Alias column of the field and specify an alias for it.
    5. Double-click the Data Type column of the field and select Long from the drop-down menu.
The Field name, Alias, and Data Type field in the attribute table.
  1. On the top ribbon, on the Fields tab, click Save.
The Save option in the Changes group.
  1. Follow Step 2 to add a new field to the class for the y-value.
<Null> results in the X and Y-values column.
  1. Calculate the x-value field.
    1. In the table view, right-click the x-value field header and select Calculate Field.
    2. In the Calculate Field window, select Arcade from the Expression Type drop-down menu.
    3. Type the following expression and click Verify.
Round(Geometry($feature).X, 6)
The x-value expression configured.
  1. When the message, “Expression is valid” is returned, click OK.
The
  1. Calculate the y-value field.
    1. In the table view, right-click the field’s header for the y-value and select Calculate Field.
    2. In the Calculate Field window, select Arcade from the Expression Type drop-down menu.
    3. Type the following expression and click Verify.
Round(Geometry($feature).Y, 6)
The y-value expression configured.
  1. When the message, “Expression is valid” is returned, click OK.

The image shows the attribute table with the XY values in meter.

The results of the XY values in the attribute table.

Optionally, calculate the XY values in decimal degrees.

  1. Open the ArcGIS Pro project.
  2. Add a new field to the feature class in ArcGIS Pro for the x-value.
    1. In the Contents pane, right-click the layer and click Attribute Table.
    2. In the attribute table, click Add Field The Add Field icon..
    3. In the Fields view, specify a name for the field in the Field Name column.
    4. Double-click the Alias column of the field and specify an alias for it.
    5. Double-click the Data Type column of the field and select Double from the drop-down menu.
The Field Name, Alias, and Data type in the attribute table.
  1. On the top ribbon, on the Fields tab, click Save.
The Save option in the Changes group.
  1. Follow Step 2 to add a new field to the class for the y-value.
  2. Calculate the x-value field.
    1. In the table view, right-click the x-value field header and select Calculate Field.
    2. In the Calculate Field window, select Arcade from the Expression Type drop-down menu.
    3. Type the following expression and click Verify.
//To populate X coordinate in decimal

function MetersToLon(x) {

    var originShift = 2.0 * PI * 6378137.0 / 2.0;

    var lon = (x / originShift) * 180.0;
        
    return Round(lon, 3);
}

return MetersToLon(Round(Geometry($feature).X, 6));
The x-value expression is configured in the expression box.
  1. When the message, “Expression is valid” is returned, click OK.
  1. Calculate the y-value field.
    1. In the table view, right-click the y-value field header and select Calculate Field.
    2. In the Calculate Field window, select Arcade from the Expression Type drop-down menu.
    3. Type the following expression and click Verify.
//To populate Y coordinate in decimal:

function MetersToLat(y) {

    var originShift = 2.0 * PI * 6378137.0 / 2.0;

    var lat = (y / originShift) * 180.0;

    lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
    return Round(lat,3);
}
return MetersToLat(Round(Geometry($feature).Y, 6));
The y-value expression is configured in the expression box.
  1. When the message, “Expression is valid” is returned, click OK.

The image below shows the attribute table with the calculated XY values in decimal degrees in ArcGIS Pro.

The calculated XY values in decimal degrees.

Article ID:000028012

Software:
  • ArcGIS Pro 2 x
  • ArcGIS Pro 2 7 x
  • ArcGIS Pro 2 8 x
  • ArcGIS Pro 3 0

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic