The Calculate Field tool calculates field values on a new or existing field. The output will always be a new layer in your ArcGIS Enterprise portal contents.
Analysis using GeoAnalytics Tools
Analysis using GeoAnalytics Tools is run using distributed processing across multiple ArcGIS GeoAnalytics Server machines and cores. GeoAnalytics Tools and standard feature analysis tools in ArcGIS Enterprise have different parameters and capabilities. To learn more about these differences, see Feature analysis tool differences.
Examples
Suppose you have collected sales data for a chain of supermarkets across the country. You currently have values for the total amount of sales by year in an existing field named TotalSales, and you want to calculate the total sales for each location. You want the field to be represented by the sum of the total sales in 2016 and 2017. Using those fields in the expression, you calculate the field value as $feature["Sales2016"] + $feature["Sales2017"].
Suppose you have GPS measurements that record the location, time, bus ID, and speed of the buses in a city. You want to create a new field named SpeedFrom3 that averages the speed of the last three recorded GPS measurements for each feature. For this calculation, you would use a track-aware calculation, where the track is a bus denoted by the bus ID. The calculation to determine the average speed of the previous three time steps and the current time step is average($track.field["speed"].history(-4)).
Usage notes
Calculate Fields is completed on tables, point, line, or area features.
You can only calculate values for a single field at a time.
You can either calculate values in a field that already exists, or create a new field by specifying a new field name.
Expressions are created using Arcade expressions.
Learn more about Arcade expressions in Calculate Field
Your calculation can optionally be track aware. Track-aware equations use Arcade expressions that use track functions.
To include a track aware-calculation, you must do the following:
- Use a layer that is time-enabled and of time type instant.
- Select The expression is track aware.
- Select the fields used to identify tracks.
Tracks are represented by the unique combination of one or more track fields. For example, if the fields flightID and Destination are used as track identifiers, the following features [ID007, Solden] and [ID007, Tokyo] would be in two separate tracks, since they have different values for the field Destination.
Applying a time interval boundary segments tracks at a defined interval. For example, if you set the time interval boundary to be 1 day, starting at 9:00 AM on January 1, 1990, each track will be truncated at 9:00 AM for every day and analyzed within that segment. This split is a fast way to accelerate computing time, as it quickly creates smaller tracks for analysis. If splitting by a recurring time interval boundary makes sense for your analysis, it is recommend for big data processing. Your analysis must be track aware to set a time boundary.
Output features will return the fields in the input. If you calculated values for a new field, that field will additionally be included.
If Use current map extent is checked, only the features that are visible within the current map extent will be analyzed. If unchecked, all input features in the input layer will be analyzed, even if they are outside the current map extent.
Limitations
Only one field can be modified at a time.
Calculate Field will always produce a new feature layer, and will not edit your input dataset.
ArcGIS API for Python example
The Calculate Field tool is available through ArcGIS API for Python.
This example calculates a new field representing the year of an earthquake occurrence. It then shows the modified data using a Pandas DataFrame.
# Import the required ArcGIS API for Python modules
import arcgis
from arcgis.gis import GIS
from arcgis.geoanalytics import manage_data
from arcgis.features import FeatureLayer
# Connect to your ArcGIS Enterprise portal and check that GeoAnalytics is supported
portal = GIS("https://myportal.domain.com/portal", "gis_publisher", "my_password", verify_cert=False)
if not portal.geoanalytics.is_supported():
print("Quitting, GeoAnalytics is not supported")
exit(1)
# Define the feature layer you're interested in using for analysis
earthquake_data_url = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Earthquakes_Since1970/FeatureServer/0"
earthquake_data = FeatureLayer(earthquake_data_url)
# Calculate the year number from the date_ field
calculate_field_result = manage_data.calculate_fields(input_layer = earthquake_data,
field_name = "year_num",
data_type = "Integer",
expression = "Year($feature.date_)",
output_name = "Earthquake_occurence_years")
# Visualize the results as a Pandas DataFrame when running Python in a Jupyter Notebook
import pandas as pd
features = calculate_field_result.layers[0].query()
df = pd.DataFrame.from_records(pd.DataFrame(features.value['features'])["attributes"])
df
Similar tools
Use Calculate Field to calculate values for features in a new or existing field. Other tools may be useful in solving similar but slightly different problems.
Map Viewer analysis tools
If you would like to detect features in a time-enabled layer, use the GeoAnalytics Tools Detect Incidents.
ArcGIS Desktop analysis tools
The GeoAnalytics Tools Calculate Field is also available in ArcGIS Pro.
If you want to calculate values on an input and modify your existing data, use the Calculate Field tool in the Data Management toolbox in ArcGIS Pro.
To run this tool from ArcGIS Pro, your active portal must be Enterprise 10.6 or later. You must sign in using an account that has privileges to perform GeoAnalytics Feature Analysis.