Linking documents to Spatial data

In order to link documents to Spatial data, we need to look at Actions

Adding an Image to a file

We want to an an image of Rothera to our Depots file. To do that, we need to add a field to the Attribute table, add the image URL/filepath, and then create an Action to let you open the file from QGIS.

First off, let's add an Attribute field.

  1. Open Layer Properties

  2. Navigate to the Fields Tab, and toggle Editing.

  3. Create a new Field:

    1. Name: "image"

    2. Type: "Text (string)"

    3. Length: 255

    4. Click Ok

  4. Click "Apply"

You should now have a new table field. It will be empty, but that's where we want to add the file path to the image. We want to tell QGIS that this field contains file paths.

Adding a File path Widget

  1. Navigate to the Attributes Form in the Layer Properties

  2. Select the image field

  3. Set the Widget Type to Attachment

  4. Click OK

Now, you will be able to add the file path to your table.

Adding a File Path

  1. Open the Attribute table (right-click on the layer, and select "Attribute Table"

  2. Scroll down to Rothera (Name = R18T in the table)

  3. Click on the ... symbol

  4. Select the file you want to link to (in this case, rothera_image.jpg)

  5. Click Save Edits, and toggle Editing OFF (clicking the pencil symbol)

You should now have a file that contains a link to an image.

Creating an Action

We now want to create an Action that lets users open files straight from the viewer.

  1. Open the Actions tab for in Layer Properties

  2. Click the + to add a new Action. This will open an "Add New Action" dialog box. Fill in the following:

    1. Type = Open

    2. Toggle all the Actions Scopes on.

    3. Click the dropdown next to "Insert"

      1. Select "image" - this will fill in the text box with [%image%]

    4. Toggle "Show in Attribute Table"

    5. Ensure you select "Separate Buttons"

Now, you have an Action! Let's check if it works:

  1. Open your layer's Attribute Table

  2. Scroll to the Rothera row

  3. You should see a button saying "Opens an Image"

  4. Click it, and it opens the linked image!

This method can be used to link any kind of file in QGIS

Last updated