GeoEco.DataManagement.Fields.Field.CalculateArcGISFields
- classmethod Field.CalculateArcGISFields(table, fields, pythonExpressions, where=None, modulesToImport=None, statementsToExecFirst=None, statementsToExecPerRow=None)
Calculates values for one or more fields of a table using Python expressions.
Requires: ArcGIS Pro 3.2.0 or later or ArcGIS Server equivalent to ArcGIS Pro 3.2.0 or later.
- Parameters:
table (
str) – Table that contains the fields to calculate. Minimum length꞉ 1. Must exist.pythonExpressions (
listofstr) –Python expressions to evaluate for each field. There must be one expression for each field.
For each row of the table, this function updates the values of the specified fields by evaluating their corresponding expressions using the Python
eval()function. In your expressions, you can access the value of any field by referencing the field as an attribute of therowobject. For example, if your table contains aSampledSSTfield and you want to calculate theActualSSTfield from it, you might calculateActualSSTwith the following expression:row.SampledSST * 0.075 + 3.0
Your expression may be any Python statement appropriate for passing to the
eval()function. It must evaluate to a data type that is appropriate for the field’s data type:For string, text, or character fields, return a
str.For integer fields, return an
int.For floating point fields, return a
float.For date or datetime fields, return
datetime.To set the field to a database NULL value, return Python
None.
Other database data types might work if the appropriate Python data type is used, but these have not been tested.
For more information on Python syntax, please see the Python documentation.
where (
str, optional) –SQL WHERE clause expression that specifies the rows to include. If not provided, all of the rows will be included. If provided but the underlying storage format does not support WHERE clauses, an exception will be raised.
The exact syntax of this expression depends on the underlying storage format. If the underlying data store will be accessed through ArcGIS, this article may document some of the possible syntax, but not all of it may be supported through ArcGIS’s underlying Python API.
Minimum length꞉ 1.
modulesToImport (
listofstr, optional) – Python modules to import prior to evaluating the expressions. If you need to access Python functions or classes that are provided by a module rather than being built-in to the interpreter, list the module here. For example, to be able to use thedatetimeclass in your expressions, list thedatetimemodule here. In your expressions, you must refer to the class using its fully-qualified name,datetime.datetime.statementsToExecFirst (
listofstr, optional) –Python statements to execute prior to looping through the rows of the table. The statements are executed sequentially using the Python
exec()function. You can use Python statements to perform initialization tasks such as setting variables that you reference from your field expressions. For example, you might want to perform a calculation on all of the rows that involves the current date and time, but you want the date and time to remain constant while the rows are being updated. To obtain the current date and time, you know you can import thedatetimemodule and then invokedatetime.datetime.now(). But you do not want to put this into your field expressions because the value will change as the system clock ticks during your computations. Instead you can set thenowvariable using the statement:now = datetime.datetime.now()
and then reference it from your field expressions. (Don’t forget to add
datetimeto the list of modules to import first.)statementsToExecPerRow (
listofstr, optional) – Python statements to execute for every row after the row is retrieved but before the field expressions are evaluated. The statements are executed sequentially using the Pythonexec()function. You can use Python statements to perform arbitrary tasks prior to evaluating your expressions. For example, your table’s rows may represent files from which you want to extract a piece of metadata, but the extraction code cannot be expressed in a single statement. You could provide the Python statements needed to open each file, extract the metadata, and assign it to a variable. Your field expression could then reference the variable, causing the metadata value to be stored in the field.
- Returns:
Table that contains the fields to calculate. Minimum length꞉ 1. Must exist.
- Return type: