Calculating Geometry Attributes

This tutorial demonstrates calculating geometry attributes of vector features in QGIS from the Field Calculator and with the Add Geometry Attributes tool.

Included in this tutorial:

  • Option 1: Using the Field Calculator to calculate geometry: accessing geometry functions, finding and changing measurement units, and two examples (calculating the area of polygons and coordinates of points)

    Option 2: the Add Geometry Attributes tool

Software version in examples: QGIS-LTR 3.40.5-Bratislava

Tutorial Data: The tutorial includes demonstration with sample data available here.

Credits: Sally Kaye (2025)

 

Option 1: From the Field Calculator

Calculating geometry attributes can be done as a field calculation, which is covered in Adding and Calculating Fields in an Attribute Table

Accessing geometry functions

Open the Field Calculator by clicking the abacus icon in the attributes table, attributes toolbar, or fields tab in layer properties. Geometry functions can be found under the Geometry dropdown in the center menu of the field calculator.

accessing geometry functions in the Field Calculator

Finding and changing measurement units

Some geometric field calculations rely on the assigned ellipsoid and measurement units of the project. To find these current parameters in your project, navigate through Project > Properties > General. Under Measurements, use the dropdown menus to view options for units for distance measurement and units for area measurement

Below, we demonstrate viewing these parameters and changing the default distance and area measurement units to miles and square miles, respectively.

Click OK to apply measurement unit changes. 

viewing and changing measurement units in Project Properties

Example 1: Calculating the Area of Polygon Features

The demonstration below shows calculating the area of the polygon features (in the Tracts_wTable layer) in square miles using the measurement units we changed in the step above—and creating a new field in the layer’s attribute table (called “Area_SqMiles”) to store the values. 

QGIS has two options to calculate area in the Field Calculator: 

  • $area: calculates the area of the feature based on the project’s ellipsoid and measurement units, shown above (ellipsoidal).

  • area($geometry): calculates the area of the feature based on the layer’s CRS and units (planimetric).

In the example below, we choose the $area function, so our area is calculated with the project measurement units. 

Click OK to save the new calculated field. The attribute table updates automatically with the new field appended to the right.

Then, we click the save button in the attribute table to save changes and toggle editing off.

calculating area with the Field Calculator

Example 2: Calculating the coordinates of points features

The demonstration below uses geometry functions in the field calculator to calculate the X- and Y-coordinates of point features.The tutorial data used for this demonstration already has two pairs of fields with coordinates (one set calculated in feet and the other in decimal degrees). In this tutorial, we will again calculate the coordinates in feet using the layer CRS. 

We execute the field calculator tool twice, once with the x($geometry) function and again with the y($geometry) function to calculate both coordinates.

As in example 1, we check the results of the calculator in the attribute table and save changes.

calculating point coordinates with the Field Calculator

More geometry calculations

More geometric functions can be found under geometry in the function list of the field calculator. 

For polyline fields, use $length to calculate length based on project ellipsoid and unit settings. Use length3D($geometry) to calculate length based on layer CRS and units.


Option 2: the Add Geometry Attributes tool

The Add Geometry Attributes tool generates a new layer that is a copy of the source layer with geometry fields added to the attribute table. 

Find this tool in the Processing Toolbox under Vector Geometry. 

In the Add Geometry Attributes dialogue box, the demonstration below shows the following parameters:

  • Input layer: using the dropdown menu to select the layer to calculate geometry for. We select the Tracts_wTable polygon layer,

  • Calculate using:  using the dropdown menu to select whether to calculate measurements using the Layer CRS, Project CRS, or project ellipsoid and its associated units. In the example, we calculate area and perimeter using the layer CRS (NAD83 New York/Long Island in US feet).

  • Output (labeled Added geom info): By default, the tool generates a temporary layer and or adds it to the current project. You can also choose to create a new dataset file by clicking the three-dot button to the right and specifying a name and location for saving the new file.

Then, we open the attribute table to check the results of the tool. Because we ran the tool with a polygon layer, the output dataset table now includes new ‘area’ and ‘perimeter’ fields.

The same tool calculates length for polyline features and coordinates for points features. 

calculating geometries with the Add Geometry Attributes tool

 
Next
Next

Attribute Field Properties