QGIS Planet

Using Data Defined Overrides in QGIS

Using Data Defined Overrides are a powerful tool in QGIS, but I’ve got the impression that too little people use this feature. So in this blog post you can learn what they are and I’ll show you a simple example of how to use them. You will notice this blog post is pretty long, but that doesn’t mean Data Defined Overrides are difficult, they just have loads of options and I wanted to show you every step I took to use them.

What are Data Defined Overrides?

In QGIS you can use data from a layer or an expression to change the value of a setting in a layer for that specific map object. This means that a setting is dynamically changed based on a value in the attribute table of that object or a value that is generated using an expression. In other words, if you use a Data Defined Override, the manually entered setting is ignored, and instead something else is used.

Where do I find these Data Defined Overrides?

If you see a button like this one: next to a symbology or label setting, then that’s a setting you can change using Data Defined Overrides. You will notice this button is available all over the place in the symbology and label settings of a layer.

How to use Data Defined Overrides?

If you click on a button. A menu will open:

In this menu you will find different ways to enter a Data Defined Override. The first, and maybe simplest way is to select “Field” in this menu. This will show a list of fields that can be used. When you select one of the available fields, the content for that field will be used as a setting.

Another simple way to create a Data Defined Overrides is the Assistant.

If you click on that option, a new window will open:

In that window you get information on what kind of value QGIS expects for this setting. There is also the option to select a field or use the expression editor using the button in this settings window. In the example above you see the Assistant for the Rotation setting. And you will see it has a lot more options than just the field. The content of this Assistant window will be different depending on the setting you want to override.

Another way to use expressions to create Data Defined Overrides, is selecting “Edit” in the main Data Defined Override menu. This option will also allow you to edit the expression afterwards, if you want to change it.

In the Expression Builder you can use all possibilities the expressions give you, but you have to make sure the result of your expression is a value the setting expects. The expected format is shown under the expression input box. The preview of the expressions result is a good way to check if the result are compatible with the expected format.

The button turned yellow!

If a Data Defined Override is used the turns into . That way QGIS notifies you that the setting itself is ignored by the program, but instead the Data Defined Override is used. If you want disable the Data Defined Override, you can go to edit and remove the expression or you can select the option “Clear” after you pressed the button.

What can I enter into a Data Defined Override?

The answer to that question depends on the setting you want to override. The Expression builder or the Assistant will probably make it clear what kind of value from a field or expression is expected. For example:

  • The setting rotation will expect a “double” value between 0 and 360. So 122.5 would be a valid value.
  • An opacity setting will expect an “integer” value between 0 and 100. So 50 would be a valid value, but 50.1 wouldn’t.
  • A color expects a “text” in one of the following kinds of forms:
    • [r,g,b,a] where r is red, g is green, b is blue and a is the alpha value. Each of these is an integer value between 0 and 255. The entire setting without the square brackets must be a text. So for example ‘250,25,100,200’ including the single quotes would be a valid color setting.
    • Hex color codes in the forms #AARRGGBB or #RRGGBB as a text value like they are used in HTML and CSS are possible to define a color. So for example ‘#FF5000’ is a possible color.
    • A third way to define a color is to use the name of the color. A list of color names can be found on https://developer.mozilla.org/en-US/docs/Web/CSS/named-color. So for example ‘skyblue’ is a possible color.

Units like degrees or percentages are not part of the value. QGIS will assume these units based on the setting you want to override. Sometimes the units are a separate setting, and so for a width you first set the unit setting and for the main width setting you can use the Data Defined Override.

A simple example

To make Data Defined Overrides easier to understand I’ll show it with this simple example below. We start with a simple point layer. In this example the points are the locations of arrows we want to place along a route. We want the arrows to be rotated so they are aligned along the route. To accomplish this I have added a field called “rotation” and for each point I have entered a number into that field that has the rotation value (between 0° and 360°) of each arrow.

On the map below you can see each point labelled with it’s rotation value.

After that we will change the symbol of the points to arrows. You can style them anyway you want, but I chose to make them as a simple marker with a simple red arrows. At this moment all arrows will point up.

To change the rotation we will now use Data Defined Overrides. First we have to click on the button next to the rotation setting. There I click on the option “Field”, and select the field “orientation” I previously created in my shapefile.

After I did that, you will see that each arrow is rotated based on its value in the field “rotation” in my shapefile.

After that I also added the route as a separate blue layer and added the field “rotation” also as a label on top of the arrows. I also used Data Defined Override for the rotation setting of the label and that results in the map below.

Another example

As said before you can find Data Defined Overrides in lots of settings. In the example below I used the same “rotation” setting on the field “Size”. Ans I used “Meters at scale” as unit for Size.

To conclude

I hope this explanation helps you understand that Data Defined Overrides are a powerful tool to create symbologies. I used the a lot in my examples for Geometry Generators you can find on Codeberg, because those two QGIS functionalities make a great combination. But more about that will follow in one of the next posts on this blog.

Please tell about how and why you use Data Defined Overrides in QGIS in the comments below. I’d love to hear about other use cases.

Learn More

基盤地図情報の数値標高モデル(DEM)をQGISに追加しよう - QGIS LAB by MIERUNE

はじめに地形解析や3D地図作成には、高精度の標高データが必要になる場合があります。その際に便利なのが、国土地理院が提供する基盤地図情報の数値標高モデル(DEM)です。このDEMデータは、日本全国を網羅する高品質な標高データとして無料で利用できます。この記事では、基盤地図情報の数値標高モデルをQGISに追加する具体的な手順を紹介します。基盤地図情報とは基盤地図情報とは、地図データを使った分析において...
Learn More

QField 3.6 “Gondwana”: Locking on greatness

Building on top of the last release which introduced background tracking, this development cycle focused on polishing functionalities and building on top of preexisting features. The variety of improvements is sure to make our diverse user base and community excited to upgrade to QField 3.6.

Main highlights

One of the most noticeable improvement in this version is the addition of “map preview rendering”. QField now renders partial map content immediately beyond the edge of the screen, offering a much nicer experience when panning around as well as zooming in and out. Long-time QGIS users will recognise the behaviour, and we’re delighted to bring this experience to the field

This upgrade was the foundation upon which we built the following enhancement: as of QField 3.6, using the “lock to position” mode now keeps your position at the very center of the screen while the canvas slips through smoothly. This greatly improves the usability of the function as your eyes never need to spend time locating the position within the screen: it’s dead center and it stays there!

Reminder, the “lock to position” mode is activated by clicking on the bottom-right positioning button, with the button’s background turning blue when the mode is activated.

The improvements did not stop there. Panning and zooming around used to drop users out of the lock mode immediately. While this had its upsides, it also meant that simple scale adjustments to try and view more of the map as it follows the position was not possible. With QField 3.6, the lock has been hardened. Moving the map around will temporarily disable the lock, with a visual countdown embedded within a toast message informs users of when the lock will return. An action button to terminate the lock is located within the toaster to permanently leave the mode.

Moving on to QFieldCloud, this cycle saw tons of improvements. To begin with, it is now possible to rely on shared datasets across multiple cloud projects. Known as localised data paths in QGIS, this functionality enables users to reduce storage usage by storing large datasets in QFieldCloud only once, serving multiple cloud projects, and also easing the maintenance of read-only datasets that require regular updates.

QFieldSync users will see a new checkbox when synchronising their projects, letting them upload shared datasets onto QFieldCloud.

Furthermore, QField has introduced a new cloud project details view to provide additional details on QFieldCloud-hosted projects before downloading them to devices. The new view includes a cloud project thumbnail, more space for richer description text, including interactive hyperlinks, and author details, as well as creation and data update timestamps. Finally, the view offers a QR code, which allows users to scan it quickly and access cloud projects, provided they have the necessary access permission. Distributing a public project has never been easier!

Beyond that, tons more has made its way into QField, including map layer notes viewable through a legend badge in the side dashboard, support for feature identification on online raster layers on compatible WMS and ArcGIS REST servers, atlas printing of a relationship’s child feature directly within the parent feature form, and much more. There’s something for everybody out there.

Focus on feature form polishing

This new version of QField coincides with the release of XLSForm Converter, a new QGIS plugin created by OPENGIS.ch’s very own ninjas. As its title implies, the plugin converts an XLSForm spreadsheet file (.xls, .xlsx, .ods) into a full-fledged QGIS project ready to be used in QField with a pre-configured survey layer matching the content of the provided XLSForm.

This was a golden opportunity to focus on polishing QField’s feature form. As a result, advanced functionalities such as data-driven editable flag and label attribute properties are now supported. In addition, tons of paper-cut bugs, visual inconsistencies, and UX shortcomings have been addressed. Our favourite one might just be the ability to drag the feature addition drawer’s header up and down to toggle its full-screen state 🙂

Learn More

[Blog] New API tools give you more user management options!

Enhance user management in Mergin Maps with the Python API: automate user creation, manage roles, and integrate processes seamlessly.
Learn More

OpenStreetMapとは?QGISでも活用できるオープンデータプロジェクト - QGIS LAB by MIERUNE

はじめに「OpenStreetMap(OSM)」は、街中の自動販売機やゴミ箱からキャンプ場まで様々な種類の地物の情報をオープンデータとして提供しているプロジェクトです。この記事では、OpenStreetMapの特徴と、QGISでの具体的な活用方法について解説します。OpenStreetMapとは?OpenStreetMapとは、誰でも自由に利用できる地図データを作成するプロジェクトです。2004年...
Learn More

QGISでCSVやExcelなどの表形式のデータをGISデータに結合する方法 - QGIS LAB by MIERUNE

はじめにQGISでは、GISデータと表形式のデータを組み合わせることで、より深い分析や視覚化が可能になります。この記事では、QGISの「テーブル結合」機能を使って、GISデータに表形式のデータを結合する方法を紹介します。この機能を用いることで、属性テーブルの活用の幅を広げることができます。テーブル結合とは?QGISのテーブル結合機能は、複数の属性テーブルに共通する列の値を用いて、1つのテーブルに情...
Learn More

Speed up your analytics with the new MovingPandas 0.22 and Trajectools 2.6

The latest releases of MovingPandas and Trajectools come with many “under the hood” changes that aim to make your movement analytics faster:

  1. Instead of immediately creating a GeoPandas GeoDataFrame and populating the geometry column with Point objects, MovingPandas now has “lazy geometry column creation” that holds off on this operation until / if the geometries are actually needed. This way, for many operations, no geometry objects have to be generated at all.
  2. MovingPandas TrajectorySplitters now support parallel processing and Trajectools uses parallel processing whenever available (e.g. for adding speed & direction metrics, detecting stops, splitting trajectories).
  3. When a minimum length is specified for trajectories, MovingPandas now avoids computing the total trajectory length and, instead, immediately stops once the threshold value has been reached (“early skip”).
  4. Trajectools now offers the option to skip computation of movement metrics (speed & direction). This way, we can skip unnecessary computations and leverage the lazy geometry column creation, wherever applicable.

Let’s have a look at some example performance measurements!

Example 1: MovingPandas ValueChangeSplitter

The ValueChangeSplitter splits trajectories when it detects a value change in the specified column. This is useful, for example, to split up public trajectories that contain a “next_stop” column.

The following graph shows ValueChangeSplitter runtimes for different minimum trajectory length settings (from 0 to 1km, 100km, and 10,000km):

We see that the new, lazy geometry column initialization outperforms the old original code in all cases (e.g. 57% runtime reduction for 1km), except for the worst-case scenario, when the original implementation discards all trajectories as too short right from the start. (For most use cases, min_length will be set to rather small values to avoid creation of undesired short trajectory fragments, similar to sliver polygons in classic geometry operations.)

Additionally, we can engage multiprocessing by setting the n_processes parameter, e.g. to the number of CPUs to achieve further speedup:

Example 2: Trajectools

By applying all above-mentioned speedup techniques, Trajectools is now considerably faster. For example, the following runtime reductions can be achieved by deactivating the “Add movement metrics (speed, direction)” option in the algorithm dialog:

  • Create trajectories: 62%
  • Spatiotemporal generalization (TDTR): 78%
  • Temporal generalization: 81%
  • Split trajectories at stops: 53%

I have also updated the default trajectory points output style. It now uses a graduated renderer to visualize the speed values (if they have been calculated) instead of the previously used data-defined override. This makes the style faster to customize and provides a user-friendly legend:

For more infos, have a look at:

Enjoy the latest performance increases!

Learn More

属性テーブルの列の追加と削除〜効率的な方法と注意点〜 - QGIS LAB by MIERUNE

はじめにQGISで扱う地物では、地物に関連する情報を属性テーブルに記録することができますが、作業の途中で属性テーブルの列(フィールド)を増やしたり減らしたりしたい場合があるかもしれません。この記事では、属性テーブルの列の追加・削除の方法、および、注意点について説明します。属性テーブルに列を追加する属性テーブルに列を追加する手順を説明していきます。QGISでレイヤパネルで列を追加したいレイヤを右クリ...
Learn More

QGISでジオリファレンスを行う方法〜紙地図・画像を地図に追加する手順〜 - QGIS LAB by MIERUNE

はじめに紙の地図やスキャンした図面などの画像データには位置情報が付与されていないため、GIS上で正しい位置に表示することができません。この問題を解決するのが「ジオリファレンス」という作業です。この記事では、QGISを使って地図画像に座標情報を与える「ジオリファレンス」について、基本的な考え方と具体的な手順を紹介します。ジオリファレンスとはジオリファレンスとは、画像や図面に地理的な位置情報(座標)を...
Learn More

GISデータのエクスポート手順〜GeoPackageやCSVに変換しよう〜 - QGIS LAB by MIERUNE

はじめにQGISでは、一時的に作成したレイヤを保存したり、異なるファイル形式に変換するといった機会が多くあります。そんなときに役立つのが、「エクスポート」機能です。この機能を使えば、作業途中のレイヤをファイルとして保存したり、形式を変換して出力したりすることができます。この記事では、「名前を付けて保存」の基本的な使い方と、実際のユースケースを紹介します。エクスポート機能とは「エクスポート」機能は、...
Learn More