Nota:
The Field Calculator task is no longer supported in ArcGIS Online as of March 2021 or in versions of ArcGIS Enterprise 10.9 or higher.
The Field Calculator task updates values in one or more fields based on an expression you provide. The fields to update can be existing fields or a new fields that you create as part of the task request. The expression can use values from other fields. The result of this task is a new layer with all the fields from the input layer as well as any new fields you create. Field values are updated according to the expressions you provide.
Request URL
http://<analysis url>/FieldCalculator/submitJob
Request parameters
Parameter | Description |
---|---|
inputLayer (Required) | The layer containing the field to be updated. The layer can be one of the following:
Examples:
If a <where clause> is provided, only those records that match the WHERE clause will be written to the resultLayer. |
expressions (Required) | A list of fields and expressions. The general form is as follows:
Field To update an existing field, supply the name of the field in <field_description>. For example, to update values in a field named POP2014, use the following:
To create a new field, supply the following in the <field_description>:
Example: add a new field named POPDEN:
Expression To use the value of an existing field in an expression, surround the field name with exclamation points. For example, to calculate a population density value based on the value of the field POP divided by the field AREA, use the following:
Python is used to interpret expressions. The Field Calculator task uses the ArcGIS geoprocessing tool Calculate Field to perform all calculations. For more examples of expressions, see the Calculate Field tool reference documentation. As you read this tool reference page, keep the following in mind:
Working with strings When assigning strings to text fields, values must be in single quotation marks. For example, to assign the string VACANT to a field, use the following: "expression":" 'VACANT' ". Strings can be concatenated using the plus sign (+). Example: Create a field named FULL_NAME and calculate its value to be the concatenation of STREET_NAME and STREET_TYPE. You can use Python string functions on field values. For example, to uppercase values in the field LotStatus, use the following: "expression": "!LotStatus!.upper()"
Working with numbers Functions in Python's math module can be used. For example, to calculate the square root of the values in the POP field, use the following: "expression": "math.sqrt(!POP!)" The math module provides number-theoretic and representation functions, power and logarithmic functions, trigonometric functions, angular conversion functions, hyperbolic functions, and mathematical constants. To learn more about the math module, see the Python help.
Working with dates Functions in Python's datetime module can be used. Example: Use the datetime model to calculate the current date and time into an existing field EDITDATE. The syntax for date and time constants is YYYYMMDD hh:mm:ss.
Working with geometries As shown in the Calculate Field documentation, you can access properties of feature geometry, including type, extent, centroid, firstPoint, lastPoint, area, length, isMultipart, and partCount. The syntax to access geometry properties is !shape.<property>!. For example, to access the length property, use the following: "expression": "!shape.area!" Expressions can use the geometry area and length properties with an areal or linear unit to convert the value to a different unit of measure (for example, !shape.length@kilometers!). If inputLayer is stored in a geographic coordinate system and a linear unit is supplied (for example, miles), the length will be calculated using a geodesic algorithm. Using areal units on geographic data will yield questionable results as decimal degrees are not consistent across the globe.
Expressions can be used to calculate the geodesic area or length of a feature by using geodesicArea or geodesicLength properties combined with areal or linear units of measure. For example:
|
outputName | If provided, the task will create a feature service of the results. You define the name of the service. If an outputName value is not provided, the task will return a feature collection. Syntax: Syntax: |
context | Context contains additional settings that affect task execution. For Field Calculator, there are two settings.
Syntax |
f | The response format. The default response format is html. Values: html | json |
Response
When you submit a request, the service assigns a unique job ID for the transaction.
{
"jobId": "<unique job identifier>",
"jobStatus": "<job status>"
}
After the initial request is submitted, you can use the jobId to periodically check the status of the job and messages as described in the Checking job status topic. Once the job has successfully completed, use the jobId to retrieve the results. To track the status, you can make a request of the following form:
http://<analysis url>/FieldCalculator/jobs/<jobId>
Results access
When the status of the job request is esriJobSucceded, you can access the results of the analysis by making a request of the following form:
http://<analysis url>/FieldCalculator/jobs/<jobId>/results/<output parameter name>?token=<your token>&f=json
Parameter | Description |
---|---|
resultLayer |
The result has properties for parameter name, data type, and value. The contents of the value depend on the outputName parameter provided in the initial request.
See Feature Output for more information about how the result layer or collection is accessed. |