com.esri.arcgis.geoprocessing.tools.datamanagementtools
Class CalculateValue
java.lang.Object
com.esri.arcgis.geoprocessing.AbstractGPTool
com.esri.arcgis.geoprocessing.tools.datamanagementtools.CalculateValue
- All Implemented Interfaces:
- GPTool
public class CalculateValue
- extends AbstractGPTool
This tool is available with an ArcView or ArcEditor license, if the Spatial Analyst extension or the 3D Analyst extension is installed.
Returns a value based on a user specified python expression.
The Calculate Value tool is contained in the Data Management Tools tool box.
Software restrictions: ArcInfo only
Usage tips:
- Expressions can be created in a standard Python format ONLY. Other scripting languages are not supported.
- The CalculateValue tool will evaluate simple mathematical expressions. For example:3+59*84+(9/3)
- The CalculateValue tool allows the use of the python "math" module to perform more complex mathematical operations. The math module is accesses by preceding the desired function with "math.". For example:math.sqrt(25)math.cos(0.5)
- Constants are also supported through the math module. for example:math.pimath.e
- Variables created in either ModelBuilder or at the Command Line can be used by this tool. Simply enclose the variable name in percent signs (%). For example if you wish to divide the variable named Var1 by 100, your expression would be: %Var1% / 100. Note: in the previous expression, if Var1 = 123, the expression will return 1. To get decimal places, add decimals to the values in the expression. For example: %Var1% / 100.00 will return 1.23.
- In ModelBuilder, variables desired for use in the expression parameter cannot be connected to the CalculateValue tool. They should simply be enclosed in percent signs (see above).
- When running the CalculateValue tool at the command line, the expression parameter is treated as a string. Therefore, it must be enclosed within quotes. For example, if you wanted to add 2 and 2 at the command line, you would type:CalculateValue "2 + 2"
- The arcgis.rand() function is supported by the CalculateValue tool. 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; . For a description of the distributions and how they are generally used see Distributions for assigning random values;
- Examples of using the arcgis.rand() are: to calculate a random value derived from a uniform distribution of integers between 0 and 10, use arcgis.rand("Integer 0 10")to calculate a random value derived from a normal distribution with a mean of 10 and standard deviation of 3, usearcgis.rand("Normal 10 3")see tip above for further options and a full description of each distribution supported. Note: "arcgis.rand" should always be entered in lower case characters.
- Generally, users will type their expressions in the Expression parameter. More complicated expressions such as multiline calculations or logical operations (if, then etc) will require the use of the code block parameter. The Code Block parameter, cannot be used on its own, it must be used in conjunction with the Expression parameter.
- Variables defined in the Code Block parameter can be referenced from the expression.
- Functions can be defined in the Code Block and called from the Expression. In the example below our function will return a string wind direction based on a random input value. In Python functions are defined using the "def" keyword followed by the name of the function and the function's input parameters. In this case, the function is called "getWind" and has one parameter called wind. Values are returned from a function using the "return" keyword.
- In python, part of syntax is white space. The amount of white space does not matter as long as it is consistent throughout the code block.
- It is even possible to create the geoprocessor in the code block and use it to run other tools.
- You cannot access model variables from the code block. Such variables must be passed to the code block from the expression. This can be achieved by creating a definition in the code block and referencing the definition in the expression.
- Examples of Calculating Statistics with Calculate Value;
- The following environment settings affect this tool: Extent; workspace; and scratch workspace;
|
Constructor Summary |
CalculateValue()
Creates the Calculate Value tool with defaults. |
CalculateValue(Object expression)
Creates the Calculate Value tool with the required parameters. |
CalculateValue
public CalculateValue()
- Creates the Calculate Value tool with defaults.
Initializes the array of tool parameters with the default values specified when the tool was created.
CalculateValue
public CalculateValue(Object expression)
- Creates the Calculate Value 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:
expression - SQL Expression, the python expression to be evaluated.
getExpression
public Object getExpression()
- Returns the Expression parameter of this tool .
This parameter is SQL Expression, the python expression to be evaluated.
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 python expression to be evaluated.
This is a required parameter.
- Parameters:
expression - SQL Expression, the python expression to be evaluated.
getCodeBlock
public String getCodeBlock()
- Returns the Code Block parameter of this tool .
This parameter is String, additional python code. Code in the code block can be referenced in the expression parameter.
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, additional python code. Code in the code block can be referenced in the expression parameter.
This is an optional parameter.
- Parameters:
codeBlock - String, additional python code. Code in the code block can be referenced in the expression parameter.
getDataType
public String getDataType()
- Returns the Data type parameter of this tool .
This is an optional parameter.
- Returns:
- the Data type
setDataType
public void setDataType(String dataType)
- Sets the Data type parameter of this tool .
This is an optional parameter.
- Parameters:
dataType - null
getValue
public Object getValue()
- Returns the output_value parameter of this tool (Read only).
This is an derived parameter.
- Returns:
- the output_value
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