Lots of users need to link their geographical data with documents (photos, videos, pdf reports, manuals…). Those documents need to be stored on an already existing storage system (FTP, Nextcloud, cloud object storage, shared network folder…).
Until now, linking data and documents was a bit of a pain in QGIS, user needed to store the ressource on one side, then copy/paste the link to QGIS forms in order to update the data. Moreover, QGIS wasn’t able to preview these data when authentication was involved. Hence the need of a more integrated way.
Thanks to Lille Metropole funding, I had the chances to work on a new external storage feature that improves the situation. It’s available in QGIS 3.22.0 Białowieża released the 22 of october 2021. This version will become the next LTR by the end of February 2022.
Data & documents in QGIS: How to!
If you ever wonder how to design your geographic information system so you can attach documents to your data, here few informations to catch up. All following instructions assume you are in a relationnal database, but it would be possible to do so with files.
QGIS 3.22 is now well integrated with WebDAV and folders, maybe more in next version
First, you need to add inside your data a document field that would contain the URL towards the document you want to associate with. It’s often interesting to create a table to index all your documents and possibly contains metadata informations (author, creation data…). That would also permit to create association table in order to define many to many relationship between your data and your documents (see Creating one or many to many relations).
Finally, from your attribute forms configuration widget, you would choose the Attachment widget to display and edit the document field.
This way, it’s possible to edit document URL from form using the attachment widget and visualize it (for local and HTTP file without authentication).
So, when you want to add a file, you have to:
- put it onto your external storage system,
- copy/paste the url inside the attachment widget.
From QGIS 3.22, QGIS can act as a client to some of those external storage, that means it allows you to skip these two last steps. It can push a new document on simple drag’n drop and update the URL once it’s done. It can also retrieve the already pushed document and if needed, visualize it directly in the forms.
Available storage type
All users do not store their files the same way, so the new feature have been designed to be generic enough so it could support different type of storage system. For now, there is two possible storage types:
- Simple copy: Stores a copy of the resource on a file disk destination (which could be a local or network shared file system)
- WebDAV storage: The resource is pushed to a HTTP server supporting the WebDAV protocol. Nextcloud, Pydio or other file hosting software support this protocol.
The Select Existing file item refers to the old way of dealing with attachment, meaning that the target URL already exists. When you select a resource, no store operation is achieved, the attribute is only updated with the URL.
The Attachment widget configuration didn’t change much. You need to:
- select the storage type (remember that Select Existing File item is the old behavior where no store operation is involved),
- configure the URL used to store every file that user will select with the file widget selector, or drop onto the widget,
- define the way to authenticate to the external storage
Regarding the store URL, you can define an expression with the data defined override option if you want more control on where to push files (you can have different store location according to feature attributes for instance).
Configuration interface of a WebDAV storage in an attachment widget
Let’s start with an example
I have configured QGIS to connect to my own Nextcloud server instance using the WebDAV protocol and a classic login/password authentication. I can then:
- Retrieve already existing documents in the Nextcloud instance,
- Visualize those documents (image, video, text documents) directly in QGIS,
- Drag’n drop new documents, the data is updated with the URL of the new file stored on Nextcloud
You’ll find more information on how configuring and using this new feature in QGIS documentation.
We’re looking forwards to improve the feature for the next versions of QGIS. We would like to add new storage type (Cloud object storage for instance), rendering photo documents in map canvas, or being able to load project direcly from an external storage, for starters…