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
- Open the attribute table of the target layer.
- 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 attribute | Automatically added fields | Field description |
|---|---|---|
| POINT_X_Y_Z_M | POINT_XPOINT_YPOINT_ZPOINT_M | The x/y/z/m coordinates of the point. |
MULTIPOINT
| Geometry attribute | Automatically added fields | Field description |
|---|---|---|
| CENTROID | CENTROID_XCENTROID_YCENTROID_ZCENTROID_M | The x/y/z/m coordinates of the centroid point. |
| EXTENT | EXT_MIN_XEXT_MIN_YEXT_MAX_XEXT_MAX_Y | The minimum and maximum x/y coordinate values of the feature bounding rectangle. |
| PART_COUNT | PART_COUNT | The number of parts contained in the feature. |
POLYLINE
| Geometry attribute | Automatically added fields | Field description |
|---|---|---|
| LENGTH_GEODESIC | LENGTH_GEO | The geodesic length of the line. |
| LINE_START_MID_END | START_XSTART_YSTART_ZSTART_MMID_XMID_YMID_ZMID_MEND_XEND_YEND_ZEND_M | The x/y/z/m coordinates of the first point, midpoint by length, and last point of the line or polygon boundary. |
| CENTROID | CENTROID_XCENTROID_YCENTROID_ZCENTROID_M | The x/y/z/m coordinates of the centroid point. |
| CENTROID_INSIDE | INSIDE_XINSIDE_YINSIDE_ZINSIDE_M | The x/y/z/m coordinates of a center point inside or on the input feature. |
| PART_COUNT | PART_COUNT | The number of parts contained in the feature. |
| POINT_COUNT | PNT_COUNT | The number of points contained in the feature. |
| LINE_BEARING | BEARING | The start-to-end azimuth of the line, from 0 to 360. 0 is north, 90 is east, 180 is south, and 270 is west. |
| EXTENT | EXT_MIN_XEXT_MIN_YEXT_MAX_XEXT_MAX_Y | The minimum and maximum x/y coordinate values of the feature bounding rectangle. |
MULTIPOLYLINE
| Geometry attribute | Automatically added fields | Field description |
|---|---|---|
| LENGTH | LENGTH | The length of the line. |
| LENGTH_GEODESIC | LENGTH_GEO | The geodesic length of the line. |
| LINE_START_MID_END | START_XSTART_YSTART_ZSTART_MMID_XMID_YMID_ZMID_MEND_XEND_YEND_ZEND_M | The x/y/z/m coordinates of the first point, midpoint by length, and last point of the line or polygon boundary. |
| CENTROID | CENTROID_XCENTROID_YCENTROID_ZCENTROID_M | The x/y/z/m coordinates of the centroid point. |
| CENTROID_INSIDE | INSIDE_XINSIDE_YINSIDE_ZINSIDE_M | The x/y/z/m coordinates of a center point inside or on the input feature. |
| PART_COUNT | PART_COUNT | The number of parts contained in the feature. |
| POINT_COUNT | PNT_COUNT | The number of points contained in the feature. |
| LINE_BEARING | BEARING | The start-to-end azimuth of the line, from 0 to 360. 0 is north, 90 is east, 180 is south, and 270 is west. |
| EXTENT | EXT_MIN_XEXT_MIN_YEXT_MAX_XEXT_MAX_Y | The minimum and maximum x/y coordinate values of the feature bounding rectangle. |
POLYGON / MULTIPOLYGON
| Geometry attribute | Automatically added fields | Field description |
|---|---|---|
| AREA | POLY_AREA | The area of the polygon. |
| AREA_GEODESIC | AREA_GEO | The geodesic area of the polygon. |
| PERIMETER_LENGTH | PERIMETER | The perimeter or boundary length of the polygon. |
| PERIMETER_LENGTH_GEODESIC | PERIM_GEO | The geodesic length of the polygon perimeter or boundary. |
| CENTROID | CENTROID_XCENTROID_YCENTROID_ZCENTROID_M | The x/y/z/m coordinates of the centroid point. |
| CENTROID_INSIDE | INSIDE_XINSIDE_YINSIDE_ZINSIDE_M | The x/y/z/m coordinates of a center point inside or on the input feature. |
| LINE_START_MID_END | START_XSTART_YSTART_ZSTART_MMID_XMID_YMID_ZMID_MEND_XEND_YEND_ZEND_M | The x/y/z/m coordinates of the first point, midpoint by boundary length, and last point of the polygon boundary. |
| PART_COUNT | PART_COUNT | The number of parts contained in the feature. |
| POINT_COUNT | PNT_COUNT | The number of points contained in the feature. |
| EXTENT | EXT_MIN_XEXT_MIN_YEXT_MAX_XEXT_MAX_Y | The minimum and maximum x/y coordinate values of the feature bounding rectangle. |
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
- Add a field before writing values: for important fields, create a new field first, such as
len_morarea_m2, and replace the original field only after confirming the result. - Validate on a small set first: calculate a few features first to verify the order of magnitude, then calculate all records.
- 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
AREAandLENGTHin 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
- Calculate density for polygon features:
Density = Population / AREA
- Conditional classification:
Level = where(Value >= 80, 'A', where(Value >= 60, 'B', 'C'))
- Require multiple conditions at the same time:
Flag = where((Type == 'main') & (Value > 0), 1, 0)
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.