# 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. &#x20;

#### First off, let's add an Attribute field. &#x20;

1. Open Layer Properties
2. Navigate to the **Fields** Tab, and **toggle Editing.**&#x20;
3. Create a **new Field**:
   1. Name: "**image**"
   2. Type: "**Text (string)**"
   3. Length: **255**
   4. Click Ok
4. Click "Apply"

![Creating a new Field](https://1859916809-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MW-CoufgyGZ3iU5q9S1%2F-MW4GaQyJo6xvWto0NMC%2F-MW4OjuR9f6UCF6n20yH%2Factions1.jpg?alt=media\&token=601d3514-c455-4316-acee-45f7c1544f3a)

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&#x20;

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

![Attribute Forms in Layer Properties](https://1859916809-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MW-CoufgyGZ3iU5q9S1%2F-MW4GaQyJo6xvWto0NMC%2F-MW4PYRXGvFIoaBt9-1c%2Factions2.jpg?alt=media\&token=bdc486be-b42d-4ca0-924c-d647eff80494)

Now, you will be able to add the file path to your table. &#x20;

#### Adding a File Path&#x20;

1. Open the Attribute table (right-click on the layer, and select "Attribute Table"
2. Scroll down to Rothera (Name = R18T in the table)&#x20;
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. &#x20;

### Creating an Action&#x20;

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

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**"&#x20;

![Creating an Action](https://1859916809-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MW-CoufgyGZ3iU5q9S1%2F-MW4SHbztoB6NjKaKXpS%2F-MW4TRH58DaZWVJV-aOX%2Factions3.jpg?alt=media\&token=1f4f8485-25cc-434e-812c-9b89efc6d699)

![Dropdown for Insert](https://1859916809-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MW-CoufgyGZ3iU5q9S1%2F-MW4SHbztoB6NjKaKXpS%2F-MW4TMZshEx2uT3gdwSb%2Factions3_1.jpg?alt=media\&token=e7ac48b8-16bb-4d2d-89a9-235f7ea2c18c)

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

1. Open your layer's Attribute Table&#x20;
2. Scroll to the Rothera row
3. You should see a button saying "Opens an Image" &#x20;
4. Click it, and it opens the linked image!&#x20;

{% hint style="success" %}
This method can be used to link any kind of file in QGIS
{% endhint %}
