Published on 10.12.2024

How to speed up your QField use with attribute forms

As some of you might already know QField is a fieldwork app that’s compatible with QGIS. The application can be used to collect data from the field (outside the warm indoors office) meaning digitizing new features to layers, updating attributes of existing ones, altering the already digitized geometries or deleting earlier features. These all are very basic processes and features that many GIS experts know and use on a daily basis, yet many do the process of creating new features manually every single time. 

In this article we will introduce you to forms – a feature that requires a bit of your time when setting up the QField project, but saves a lot of time in the field. The tips here are aimed at QField users, but QGIS users who digitize a lot, will benefit from these features too.

What are the benefits?

Setting up forms makes it possible to fill in attributes with automatic values and using constraints that make sure that the data you fill in or edit is of a certain quality. Properly defined forms speed up data collection. The setting up forms is done in QGIS before the project transferred to QField and needs to be done only once for the whole project (unless you want to fiddle with it afterwards).

Some examples: a surveyor that wanders around the city collecting survey points and wants to automatically capture not only the location but also the timestamp (“it was 5:17:01 PM exactly when I saw a rabbit in this location”). 

Another example could be when an inspector performs inspections and fills out inspection forms, their workflow would be more fluent if the inspector’s name and the date of inspection would be filled in automatically (“A newly planted rosebush, seen on March 15. by inspector Clouseau”). 

Or if there is a group of people doing the fieldwork, instead of using free text fields where anyone can write whatever they like, the form can use drop down lists with fixed values (the value of the field is always “birch” or “spruce” instead of “spurce”, “spryce” or “bruce”).

A minor disclaimer before we dive into the forms any further: QField forms are similar to forms in QGIS but not exactly the same. Most of the same features are supported in QField, and those few that are not, are not there (yet) partly because the mobile interface imposes certain limitations.

What are automatic values?

Automatic values are values that are automatically given to certain fields according to specific criteria or rule(s). These are particularly useful for ensuring that certain fields are consistently and correctly filled out, without requiring manual input. The automatic values save time when collecting new features and reduce the workload of the collectors of the data.

Automatic value configurations are done in QGIS before exporting the project to QField. Open your QGIS project and navigate to the attribute table of the layer you want to configure. Right-click on the layer and go to Properties > Attribute forms

One of the most used automatic values are timestamps. It will ensure that you automatically capture the time and date when a record is created or modified. Function for that is now().

You can set the format of the timestamp with the format_date function. For instance: format_date(now(),’dd.MM.yyyy’) returns the current date in the way we are used to here in Finland. 

You can set other automatic values as well, for example:

  1. User Information: Automatically populate fields with information about the user who is making the change, such as their name or device ID. Functions:
    • @cloud_username (returns the QField cloud username)
    • @cloud_useremail (returns the QField cloud email), 
    • @user_account_name (returns current user’s operating system account name.), 
    • @user_full_name (returns current user’s operating system user name (if available))
  2. Location Data: Automatically capture the current GPS coordinates when a new record is added.
    • @position_coordinate (returns a point with the coordinate in WGS84)
    • All position functions can be found here
    • To transform the coordinates received x(transform(@position_coordinate, ‘EPSG:3067’, @project_crs )), y(transform(@position_coordinate, ‘EPSG:3067’, @project_crs ))
  3. Incremental IDs: Automatically generate IDs for new records incrementally.
    • @id – (automatically generate IDs for new records incrementally)
  4. Other useful:
    • length($geometry) (returns Insert the length of the digitized line) 
    • $area (returns the area of the current feature)
    • @qgis_os_name (returns current operating system name, e.g., ‘windows” or ‘android’)
    • @qgis_platform -(returns current qgis platform, e.g. ‘desktop’)
    • @qgis_version  (returns current qgis version e.g. ‘3.34.5-Prizren’)

What are constraints?

Constraints are rules or conditions that are applied to data fields to ensure data integrity and accuracy during data entry or editing. Constraints help prevent invalid or incorrect data from being added to your GIS datasets. 

Constraining the values you can make sure that the quality of the collected data is homogeneous and thus the data can be reused and refined. This is particularly important when the data is collected by various people. By limiting the values, for example, to a drop-down list you can make sure that each value is written correctly, can be compared to other values, and the likelihood of errors in data entry is significantly reduced compared to manually entering the information.

QGIS offers several types of constraints that can be set up through the field properties of a layer.

There are at least five different types of constraints:

  1. Expression-Based Constraints:
    • Purpose: Apply custom rules to a field using QGIS’s expression engine.
    • Example: You might require that ‘Area’ field must always be greater than zero.
    • Setup: Define the constraint using expressions like Area > 0.
  2. Field Length Constraints:
    • Purpose: Limit the number of characters allowed in a text field.
    • Example: Restrict a ‘Zip Code’ field to exactly 5 digits.
  3. Range Constraints:
    • Purpose: Restrict numeric or date fields to a specific range.
    • Example: Ensure that a ‘Temperature’ field only accepts values between -50 and 50.
  4. Unique Constraints:
    • Purpose: Ensure that each value in a specified field is unique across all records in the layer.
    • Example: In a parcel dataset, each parcel ID must be unique.
  5. Not Null Constraints:
    • Purpose: Ensure that a field is not left empty during data entry.
    • Example: A field for ‘Survey Date’ in an inspection record should not be left blank.
qfield
Examples on automatic values

So, next time you set up your QField project remember to keep in touch with automatic values and constraints! 

Profiilikuva

Joona Rissanen

Joona Rissanen is a Master of Social Sciences from Joensuu with roots deep in Savonia. His interests are open systems and solving all sorts of GIS puzzles. He has experience especially from the public sector. On his free time Joona enjoys sports and doing various tasks.