## com.esri.arcgis.geoprocessing.tools.datamanagementtools Class CalculateField

```java.lang.Object com.esri.arcgis.geoprocessing.AbstractGPTool com.esri.arcgis.geoprocessing.tools.datamanagementtools.CalculateField
```
All Implemented Interfaces:
GPTool

`public class CalculateFieldextends AbstractGPTool`

Calculates the values of a field for a The Calculate Field tool is contained in the Data Management Tools tool box.

Software restrictions: none

#### Usage tips:

• Calculate Field computes and assigns a value to the specified field of the Input table.
• Expressions can be created in a standard Visual Basic (VB) format or in a standard Python format. The formatting style of the string used for the expression should be appropriate to the environment (type).
• Python expressions can be created using properties from the geometry object; (Type, Extent, Centroid, FirstPoint, LastPoint, Area, Length, IsMultipart, and PartCount).
• Python 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.!shape.area@acres!Areal unit of measure keywords: Unit of measure keywords: ACRES | ARES | HECTARES | SQUARECENTIMETERS | SQUAREDECIMETERS | SQUAREINCHES | SQUAREFEET | SQUAREKILOMETERS | SQUAREMETERS | SQUAREMILES | SQUAREMILLIMETERS | SQUAREYARDS | SQUAREMAPUNITSLinear unit of measure keywords: CENTIMETERS | DECIMALDEGREES | DECIMETERS | FEET | INCHES | KILOMETERS | METERS | MILES | MILLIMETERS | NAUTICALMILES | POINTS | YARDS
• In the tool's dialog, an expression can be entered directly into the Expression parameter, or interactively built using the Field Calculator.
• Calculate Field will work with a selected set of features such as those created from a query in Make Feature Layer; or Select Layer by Attribute;
• The calculation can only be applied to one field per operation.
• When calculating new values for a field, existing values will be overwritten. Retain a copy of the input table before using Calculate Field in case an error is made.
• Fields are always enclosed in square brackets [ ] for VB.
• Fields are always enclosed in exclamation points ! ! for Python.
• To calculate strings to text or character fields, the string must be double-quoted (for example, "string") in the dialog box, whereas at the command line and in scripting, the double-quoted string must also be encapsulated in single quotes (for example, '"string"').
• Calculate Field can also be used to update character items. Expressions using character string should be wrapped using single quotes, for example: [CHARITEM] = 'NEW STRING'. However, if the character string has embedded single quotes, wrap the string using double quotes. For example: [CHARITEM] = "TYPE'A'".
• To calculate a field to be a numeric value, enter the numeric value in the Expression parameter; no quotes around the value are required.
• The arcgis.rand() function is supported by the CalculateField tool and the expression type must be Python. The arcgis.rand() function has been created for ArcGIS tools and should not be confused with the Python Rand() function. The syntax for the available distributions for the arcgis.rand() function can be found at The distribution syntax for random values;
• The expression and code block are connected. The code block must relate back to the expression; the result of the code block should be passed into the expression. For example:CalculateField_management C:\WUTemp\polygon_Copy.shp NEAR_X x PYTHON 'x = 5'The expression is 'x', and the code block is 'x = 5'.
• The Code Block parameter allows you to create complex expressions. You can enter the code block directly on the dialog, or as a continuous string at the command line or in scripting.
• The Python math modules and formatting are available for use in the Code Block parameter. Additional modules can be imported. The math module provides number-theoretic and representation functions, power and logarithmic functions, trigonometric functions, angular conversion functions, hyberbolic functions and mathematical constants. To learn more about the math module, see Python's help.
• When calculating joined data, you cannot calculate the joined columns directly. However, you can directly calculate the columns of the origin table. To calculate the joined data, you must first add the joined tables or layers to ArcMap. You can then perform calculations on this data separately. These changes will be reflected in the joined columns.
• In a stand-alone script, calculations using Expression Type's PYTHON option must use the arcgisscripting module. Stand-alone scripts that use win32com.client module to create the geoprocessor will fail with a "Python expression is blocked when using a dispatch based application" error.
• The expression type must be Python when running Calculate Field with ArcGIS Engine or ArcGIS Server. Visual Basic for Applications (VBA) is required for many types of VB expressions and VBA is only available when Calculate Field is run by ArcGIS Desktop. Only use Python as the expression type whenever the tool is included in a model that will be published to an ArcGIS Server.
• The following environment affects this tool: workspace;

Field Summary

Fields inherited from class com.esri.arcgis.geoprocessing.AbstractGPTool
`vals`

Constructor Summary
`CalculateField()`
Creates the Calculate Field tool with defaults.
```CalculateField(Object inTable, Object field, Object expression)```
Creates the Calculate Field tool with the required parameters.

Method Summary
` String` `getCodeBlock()`
Returns the Code Block parameter of this tool .
` Object` `getExpression()`
Returns the Expression parameter of this tool .
` String` `getExpressionType()`
Returns the Expression Type parameter of this tool .
` Object` `getField()`
Returns the Field Name parameter of this tool .
` Object` `getInTable()`
Returns the Input Table parameter of this tool .
` Object` `getOutTable()`
Returns the Output Feature Class parameter of this tool (Read only).
` String` `getToolboxAlias()`
Returns the alias of the tool box containing this tool.
` String` `getToolboxName()`
Returns the name of the tool box containing this tool.
` String` `getToolName()`
Returns the name of this tool.
` void` `setCodeBlock(String codeBlock)`
Sets the Code Block parameter of this tool .
` void` `setExpression(Object expression)`
Sets the Expression parameter of this tool .
` void` `setExpressionType(String expressionType)`
Sets the Expression Type parameter of this tool .
` void` `setField(Object field)`
Sets the Field Name parameter of this tool .
` void` `setInTable(Object inTable)`
Sets the Input Table parameter of this tool .

Methods inherited from class com.esri.arcgis.geoprocessing.AbstractGPTool
`getParameterValues, toString`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### CalculateField

`public CalculateField()`
Creates the Calculate Field tool with defaults.

Initializes the array of tool parameters with the default values specified when the tool was created.

### CalculateField

```public CalculateField(Object inTable,
Object field,
Object expression)```
Creates the Calculate Field tool with the required parameters.

Initializes the array of tool parameters with the values as specified for the required parameters and with the default values for the other parameters.

Parameters:
`inTable` - Table View | Raster Layer, the table that contains the rows from a specified field that will be calculated. The updated values will be added to this table.
`field` - Field, the field that will be updated with the new calculation.
`expression` - SQL Expression, the simple calculation expression used to create a value that will populate the selected rows.
Method Detail

### getInTable

`public Object getInTable()`
Returns the Input Table parameter of this tool . This parameter is Table View | Raster Layer, the table that contains the rows from a specified field that will be calculated. The updated values will be added to this table. This is a required parameter.

Returns:
the Input Table

### setInTable

`public void setInTable(Object inTable)`
Sets the Input Table parameter of this tool . This parameter is Table View | Raster Layer, the table that contains the rows from a specified field that will be calculated. The updated values will be added to this table. This is a required parameter.

Parameters:
`inTable` - Table View | Raster Layer, the table that contains the rows from a specified field that will be calculated. The updated values will be added to this table.

### getField

`public Object getField()`
Returns the Field Name parameter of this tool . This parameter is Field, the field that will be updated with the new calculation. This is a required parameter.

Returns:
the Field Name

### setField

`public void setField(Object field)`
Sets the Field Name parameter of this tool . This parameter is Field, the field that will be updated with the new calculation. This is a required parameter.

Parameters:
`field` - Field, the field that will be updated with the new calculation.

### getExpression

`public Object getExpression()`
Returns the Expression parameter of this tool . This parameter is SQL Expression, the simple calculation expression used to create a value that will populate the selected rows. This is a required parameter.

Returns:
the Expression

### setExpression

`public void setExpression(Object expression)`
Sets the Expression parameter of this tool . This parameter is SQL Expression, the simple calculation expression used to create a value that will populate the selected rows. This is a required parameter.

Parameters:
`expression` - SQL Expression, the simple calculation expression used to create a value that will populate the selected rows.

### getExpressionType

`public String getExpressionType()`
Returns the Expression Type parameter of this tool . This parameter is String, for a comparison of 9.2 and 9.3 geoprocessor, see This is an optional parameter.

Returns:
the Expression Type

### setExpressionType

`public void setExpressionType(String expressionType)`
Sets the Expression Type parameter of this tool . This parameter is String, for a comparison of 9.2 and 9.3 geoprocessor, see This is an optional parameter.

Parameters:
`expressionType` - String, for a comparison of 9.2 and 9.3 geoprocessor, see

### getCodeBlock

`public String getCodeBlock()`
Returns the Code Block parameter of this tool . This parameter is String, allows for a block of code to be entered for complex expressions. This is an optional parameter.

Returns:
the Code Block

### setCodeBlock

`public void setCodeBlock(String codeBlock)`
Sets the Code Block parameter of this tool . This parameter is String, allows for a block of code to be entered for complex expressions. This is an optional parameter.

Parameters:
`codeBlock` - String, allows for a block of code to be entered for complex expressions.

### getOutTable

`public Object getOutTable()`
Returns the Output Feature Class parameter of this tool (Read only). This is an derived parameter.

Returns:
the Output Feature Class

### getToolName

`public String getToolName()`
Returns the name of this tool.

Returns:
the tool name

### getToolboxName

`public String getToolboxName()`
Returns the name of the tool box containing this tool.

Returns:
the tool box name

### getToolboxAlias

`public String getToolboxAlias()`
Returns the alias of the tool box containing this tool.

Returns:
the tool box alias