Using Photos in QGIS Projects

2 minutes read

In QGIS, there are many formats of data-sets that can be used. Joins and relates help users get the best out of their data depending on the users’ needs. These tools exist out of-the-box for use by everyone. However, there are some tools or functionalities that are tricky to use as they don’t appear straightforward as many would like them to be. In this post, I showcase a method for showing images that’s related to various features in QGIS projects.

Case Scenario
You are out in the fields for an exercise/project and one of the requirements is to take pictures of features or pictures that relate to features of interest. In this case, collecting data about incidences in the farms and want to show the pictures that can help describe the incidences. Assuming you are using a mobile app, and the data is saved on memory or probably a card. Your output will resemble something like the pic below;

Screenshot of incidences in QGIS

With the incidences data loaded into the map canvas, if we check the attribute table, we have the following(As below)

Screenshot of the attribute table

In the figure above, there are four fields/columns. The image column hold the path to the images on the computer(Linux system). We need to view this image in QGIS just to deduce some decisions from this data. Let’s explore the opportunities that exist.

Under layer properties, click on attribute form  (QGIS 3.x ) or Fields(QGIS < 3.0)then choose image column. Under widget type, ensure its Text Edit

Screenshot of layer properties

Click on Actions on the properties window. Click on + to add an action. A dialog box will open

Screenshot of Action Dialogbox

In the dialog box, a number of settings are available. There is;

  • Type – This denotes the type of action that we will add. E.g Python, which expects a Python code or Unix, which expects an expression in the Unix format etc
  • Description – Gives more information on what the action is about
  • Short Name – This is the name that will be visible on the action section
  • Icon – This is icon that will appear on the action section
  • Action Scope – Where the action will be available/accessible on the QGIS project
  • Action text – The expression that will be executed when the action is triggered

In this example, I’m using Ubuntu. I will therefore use the Unix type, and set the other parameters as I need them to be. Under Action Text, I will input eog [%”image”] or automate it by writing eog and selecting the column to use on the dropdown section just below the expression section and clicking the Insert button. Ensure there is a space between eog and the [] expression.

Screenshot of Action Dialog

Click Ok to exit the dialog. Click Apply then Ok

Screenshot of added action

Select the layer,incidences, to highlight it for use with the action. on the Attributes Toolbar, click on the dropdown arrow next to the Actions Icon. The action we created will be available for selection. Select the action (The cursor will change) and click on one feature on the map canvas.

Screenshot of Image shown in QGIS

The image is shown as we expected. Bingo!!

That was cool. right? On adding actions in QGIS, great care must be taken such as the space between eog and the [] expression and also the type of action. Actions are awesome in automating tasks in QGIS. Try different functionality with actions today.

For more details, watch this Video Tutorial

Happy Hacking !!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.