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
- Open the ArcGIS Pro project.
- Add a new field to the feature class in ArcGIS Pro for the x-value.
- In the Contents pane, right-click the layer and click Attribute Table.
- In the attribute table, click Add Field .
- In the Fields view, specify a name for the field in the Field Name column.
- Double-click the Alias column of the field and specify an alias for it.
- Double-click the Data Type column of the field and select Long from the drop-down menu.
- On the top ribbon, on the Fields tab, click Save.
- Follow Step 2 to add a new field to the class for the y-value.
- Calculate the x-value field.
- In the table view, right-click the x-value field header and select Calculate Field.
- In the Calculate Field window, select Arcade from the Expression Type drop-down menu.
- Type the following expression and click Verify.
Round(Geometry($feature).X, 6)
- When the message, “Expression is valid” is returned, click OK.
- Calculate the y-value field.
- In the table view, right-click the field’s header for the y-value and select Calculate Field.
- In the Calculate Field window, select Arcade from the Expression Type drop-down menu.
- Type the following expression and click Verify.
Round(Geometry($feature).Y, 6)
- When the message, “Expression is valid” is returned, click OK.
The image shows the attribute table with the XY values in meter.
Optionally, calculate the XY values in decimal degrees.
- Open the ArcGIS Pro project.
- Add a new field to the feature class in ArcGIS Pro for the x-value.
- In the Contents pane, right-click the layer and click Attribute Table.
- In the attribute table, click Add Field .
- In the Fields view, specify a name for the field in the Field Name column.
- Double-click the Alias column of the field and specify an alias for it.
- Double-click the Data Type column of the field and select Double from the drop-down menu.
- On the top ribbon, on the Fields tab, click Save.
- Follow Step 2 to add a new field to the class for the y-value.
- Calculate the x-value field.
- In the table view, right-click the x-value field header and select Calculate Field.
- In the Calculate Field window, select Arcade from the Expression Type drop-down menu.
- 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));
- When the message, “Expression is valid” is returned, click OK.
- Calculate the y-value field.
- In the table view, right-click the y-value field header and select Calculate Field.
- In the Calculate Field window, select Arcade from the Expression Type drop-down menu.
- 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));
- 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.