CALC_ATTR_FORMULA

The CALC_ATTR_FORMULA command allows you to calculate a new attribute value (or update the value for an existing attribute) for features in a layer, based on a formula that may contain numbers, strings or other attributes. A number of functions may be used as well.

The following parameters are supported by the command:

  • FILENAME - filename of the layer to update. If an empty value is passed in, all loaded vector layers will be updated. This parameter can be listed more than once to specify multiple input files, like FILENAME="FILENAME_1" FILENAME="FILENAME_2". When running the script in the context of the main map view (including loading a workspace) you can also pass in the value 'USER CREATED FEATURES' to have the 'User Created Features' layer updated or 'SELECTED LAYERS' to have any layers selected in the Control Center If you don't pass anything in all vector layers will be operated on.
  • NEW_ATTR - specifies the attribute value to create or update. See special Attribute Name parameter details.
  • CALC_MODE - specifies the way that formula operations are performed when data types are ambiguous. Possible values are:
    • AUTOMATIC - calculations are performed as numeric if the first operand is numeric, or as string otherwise.
    • NUMERIC - calculations are performed as numeric.
    • STRING - calculations are performed as string.
  • FORMULA specifies the formula to be used to create the new attribute values. See the formula calculator reference documentation for details.

SAMPLE

Here is a sample of creating a new elevation attribute in feet from an elevation attribute (ELEV_M) in meters, including with an appended unit string.

GLOBAL_MAPPER_SCRIPT VERSION=1.00
// Create new ELEV_FT attribute with attribute in feet in any loaded layers
CALC_ATTR_FORMULA NEW_ATTR="ELEV_FT" FORMULA="ELEV_MT * 3.2808"
// Append the unit name to the new attribute
 CALC_ATTR_FORMULA NEW_ATTR="ELEV_FT" FORMULA="ELEV_FT + ' ft'"