Skip to main content

Calculate Geometry and Calculate Fields

Field calculation is used to generate or update field values in batches in the attribute table. Common uses include:

  • Calculating geometry attributes: write coordinates, length, area, perimeter, and other values for point, line, and polygon features.
  • Calculating business indicators: derive new fields from existing fields by using expressions, such as density, level, and identifier codes.

Field Calculation

  1. Open the attribute table of the target layer.
  2. In Tools in the attribute table, select:
    • Calculate geometry to write geometry attributes to fields.
    • Calculate Fields to calculate values in batches with expressions.

To learn basic attribute table operations first, such as filtering, selecting, and field management, see Editing Vector Data Attribute Tables.

Calculate Geometry

Calculate geometry writes geometry information to attribute fields. Typical outputs include:

  • Point features: X/Y coordinates, or longitude and latitude.
  • Line features: length, written in the specified unit when available.
  • Polygon features: area and perimeter, written in the specified unit when available.

The following tables summarize the available Geometry attributes for Calculate geometry and the fields that are automatically added and populated.

POINT

Geometry attributeAutomatically added fieldsField description
POINT_X_Y_Z_MPOINT_X
POINT_Y
POINT_Z
POINT_M
The x/y/z/m coordinates of the point.

MULTIPOINT

Geometry attributeAutomatically added fieldsField description
CENTROIDCENTROID_X
CENTROID_Y
CENTROID_Z
CENTROID_M
The x/y/z/m coordinates of the centroid point.
EXTENTEXT_MIN_X
EXT_MIN_Y
EXT_MAX_X
EXT_MAX_Y
The minimum and maximum x/y coordinate values of the feature bounding rectangle.
PART_COUNTPART_COUNTThe number of parts contained in the feature.

POLYLINE

Geometry attributeAutomatically added fieldsField description
LENGTH_GEODESICLENGTH_GEOThe geodesic length of the line.
LINE_START_MID_ENDSTART_X
START_Y
START_Z
START_M
MID_X
MID_Y
MID_Z
MID_M
END_X
END_Y
END_Z
END_M
The x/y/z/m coordinates of the first point, midpoint by length, and last point of the line or polygon boundary.
CENTROIDCENTROID_X
CENTROID_Y
CENTROID_Z
CENTROID_M
The x/y/z/m coordinates of the centroid point.
CENTROID_INSIDEINSIDE_X
INSIDE_Y
INSIDE_Z
INSIDE_M
The x/y/z/m coordinates of a center point inside or on the input feature.
PART_COUNTPART_COUNTThe number of parts contained in the feature.
POINT_COUNTPNT_COUNTThe number of points contained in the feature.
LINE_BEARINGBEARINGThe start-to-end azimuth of the line, from 0 to 360. 0 is north, 90 is east, 180 is south, and 270 is west.
EXTENTEXT_MIN_X
EXT_MIN_Y
EXT_MAX_X
EXT_MAX_Y
The minimum and maximum x/y coordinate values of the feature bounding rectangle.

MULTIPOLYLINE

Geometry attributeAutomatically added fieldsField description
LENGTHLENGTHThe length of the line.
LENGTH_GEODESICLENGTH_GEOThe geodesic length of the line.
LINE_START_MID_ENDSTART_X
START_Y
START_Z
START_M
MID_X
MID_Y
MID_Z
MID_M
END_X
END_Y
END_Z
END_M
The x/y/z/m coordinates of the first point, midpoint by length, and last point of the line or polygon boundary.
CENTROIDCENTROID_X
CENTROID_Y
CENTROID_Z
CENTROID_M
The x/y/z/m coordinates of the centroid point.
CENTROID_INSIDEINSIDE_X
INSIDE_Y
INSIDE_Z
INSIDE_M
The x/y/z/m coordinates of a center point inside or on the input feature.
PART_COUNTPART_COUNTThe number of parts contained in the feature.
POINT_COUNTPNT_COUNTThe number of points contained in the feature.
LINE_BEARINGBEARINGThe start-to-end azimuth of the line, from 0 to 360. 0 is north, 90 is east, 180 is south, and 270 is west.
EXTENTEXT_MIN_X
EXT_MIN_Y
EXT_MAX_X
EXT_MAX_Y
The minimum and maximum x/y coordinate values of the feature bounding rectangle.

POLYGON / MULTIPOLYGON

Geometry attributeAutomatically added fieldsField description
AREAPOLY_AREAThe area of the polygon.
AREA_GEODESICAREA_GEOThe geodesic area of the polygon.
PERIMETER_LENGTHPERIMETERThe perimeter or boundary length of the polygon.
PERIMETER_LENGTH_GEODESICPERIM_GEOThe geodesic length of the polygon perimeter or boundary.
CENTROIDCENTROID_X
CENTROID_Y
CENTROID_Z
CENTROID_M
The x/y/z/m coordinates of the centroid point.
CENTROID_INSIDEINSIDE_X
INSIDE_Y
INSIDE_Z
INSIDE_M
The x/y/z/m coordinates of a center point inside or on the input feature.
LINE_START_MID_ENDSTART_X
START_Y
START_Z
START_M
MID_X
MID_Y
MID_Z
MID_M
END_X
END_Y
END_Z
END_M
The x/y/z/m coordinates of the first point, midpoint by boundary length, and last point of the polygon boundary.
PART_COUNTPART_COUNTThe number of parts contained in the feature.
POINT_COUNTPNT_COUNTThe number of points contained in the feature.
EXTENTEXT_MIN_X
EXT_MIN_Y
EXT_MAX_X
EXT_MAX_Y
The minimum and maximum x/y coordinate values of the feature bounding rectangle.
tip

Geodesic geometry values, such as LENGTH_GEO, AREA_GEO, and PERIM_GEO, are calculated using a geodesic method. Output units follow the unit setting selected in the interface.

Coordinate System and Units

  • Geometry calculation units are strongly related to the coordinate system:
    • A projected coordinate system usually uses meters and is better suited for length and area.
    • A geographic coordinate system, using longitude and latitude, uses degrees. Direct planar length or area calculations usually do not match business expectations.
  • Recommended practice:
    • When you need results in meters or square meters, prioritize data in a projected coordinate system, or choose geodesic geometry calculation when the interface provides that option.

Recommendations

  1. Add a field before writing values: for important fields, create a new field first, such as len_m or area_m2, and replace the original field only after confirming the result.
  2. Validate on a small set first: calculate a few features first to verify the order of magnitude, then calculate all records.
  3. Pay attention to multipart features: multipart lines and polygons usually output one length or area value for the whole geometry.

Calculate Fields

Calculate Fields assigns field values in batches by using expressions. It supports common mathematical operations, logical decisions, and function calls.

AI Formula Writing

If you already know the result you want but cannot write the complete expression immediately, you can use AI to generate a draft formula from natural language, then return to the attribute table to review and run it.

AI is especially useful when you need to:

  • Assign levels based on multiple conditions.
  • Generate multiple fields at the same time.
  • Use geometry keywords such as AREA and LENGTH in a calculation.
  • Convert an existing formula into a multi-line form that is easier to review.

When asking AI, state the following as clearly as possible:

  • The target field name.
  • The fields used in the calculation.
  • The classification thresholds or judgment conditions.
  • How to handle null values, zero values, and abnormal values.

Example:

Add a density field. Calculate population density by dividing Population by AREA. If the area is 0 or the population is null, output nan.

AI may generate:

density = where(logical_or(isnan(Population), AREA == 0), nan, Population / AREA)

Another example:

Add a risk_level field. Set it to 'High' when slope is greater than 25 and rain is greater than 100. Set it to 'Medium' when slope is greater than 15 or rain is greater than 60. Otherwise, set it to 'Low'.

AI may generate:

high_risk = logical_and(slope > 25, rain > 100)
mid_risk = logical_or(slope > 15, rain > 60)
risk_level = where(high_risk, 'High', where(mid_risk, 'Medium', 'Low'))

What to Check When Using AI

  • Whether field names exactly match the attribute table.
  • Whether boundary conditions should include equality signs.
  • Whether output field names follow your naming convention.
  • Whether geometry values such as area and length match the current layer type and coordinate system method.
  • Whether null values are handled according to your business expectations.

Expression Writing Tips

  • Field references: you can usually use field names directly.
  • Conditional assignment: a common form is where(condition, x, y).
  • Logical operations: per-feature logic usually uses & for AND, | for OR, and ~ for NOT. Use parentheses to make precedence explicit.
  • Multi-line assignment: you can calculate intermediate variables first and then write to the target field, if the interface supports it.

Common Examples

  1. Calculate density for polygon features:
Density = Population / AREA
  1. Conditional classification:
Level = where(Value >= 80, 'A', where(Value >= 60, 'B', 'C'))
  1. Require multiple conditions at the same time:
Flag = where((Type == 'main') & (Value > 0), 1, 0)
warning

Expression functions and keywords may differ slightly between versions. If you need to use geometry functions, such as AREA, LENGTH, or geodesic geometry values, refer to the expression documentation in the Geoprocessing Toolbox and use the function list in the interface as the final reference.

Relationship with the Vector Calculator Tool

If you need more complex expressions, such as geometry functions, geodesic functions, or multi-line assignments, see Calculate Fields (Vector Calculator) in the Geoprocessing Toolbox. The expression systems are usually consistent or highly similar.

If you prefer to describe the requirement in natural language first and let the system generate a formula, see the blog article Writing Raster Calculator and Field Calculator Formulas with AI.

FAQ

Calculation Results Are Not as Expected

  • Check the coordinate system first: planar calculation in a geographic coordinate system produces units in degrees.
  • Then check the units: make sure the length units, such as m or km, and area units, such as m2 or km2, are selected correctly.
  • Finally, check the field type: an integer output field may truncate decimals.

Calculation Is Slow

  • Use filters first to reduce the record range to calculate.
  • Prioritize length and area calculations in a projected coordinate system to avoid unnecessary complex geodesic calculations.