2

I am searching for an expression or some assistance in changing filepaths and links to photos within attributes to relative paths.

I have used QConsolidate to create a folder with all the files and links I want.

I would like to create a single folder so I can give the folder to a client and when they install on their system they will have all the connections retained.

I have been finding info on relative paths and thought I had cracked it with @project_folder ||'/data/'|| filename

But this expression does not change the file path when the folder is moved to a different location.

2 Answers 2

1

Presumably you're using that expression to store the file path in a field. However, a regular field won't update automatically. The solution is to use either a virtual field or a default field value. In this case, I expect the default field value update will not be triggered when the @project_folder value changes, so you will be better off with a virtual field.

To create a virtual field, use the Field Calculator to create a new field with your expression, and check the option to "create virtual field"

@project_folder ||'/data/'|| filename

In this expression, filename must be the name of a field in the same layer.

enter image description here

0

The plugin QConsolidate works by me. (tested on QGIS 2.18.21)

Maybe, before export you have to configure the project: Menu Project - Properties - General - Save paths as "relative".

After using the plugin, if you open your project file with a text editor (i.e notepad ++), you see the paths are relative between the balises <datasource>./layers/xx.shp</datasource>

2
  • Thanks. I did try QConsolidate but didn't look at the project file after export. Will check again but not sure if this impacts the filepaths in the attribute table which link to geotag imagery. Would you happen to know the script fro paths in a field. Like I said I used ---@project_folder ||'/data/'|| filename--- but the path doesn't change when folder moved. I am thinking this script is close to what I need. Thanks again
    – David Cini
    Jul 10, 2018 at 0:39
  • Have you tri to add a virtual field and this code -- @project_folder ||char(92) || 'data'||char(92) || 'filename' -- Jul 11, 2018 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.