2

In order to not have to copy all the photos for my project every time I synchronise (which is beginning to take a significant amount of time), I would like to keep them in a separate folder, perhaps sister to the project, that I can copy to/from the desktop independently of the rest of the project. But putting things like ../ProjectPhotos in the default path of widget display, or Attachment Directories in Project Properties, seems to have no effect at all.

A further elaboration would be how to keep the photos somewhere in shared storage on the phone, and somewhere independent on the desktop, with both QField finding them on the phone, and QGIS on the desktop. I'm not sure at this point which would be best, or perhaps there is a reason why this is a bad thing to do, which it would be good for me to know.

2 Answers 2

1

Define a custom/project variable containing the path of the folder with the pictures. Define a separate variable for QGIS desktop and QField. Insert the variable with eval(@your_variable_name) to access the folder.

Should the folder's path change, simply change the variable's content and you're done.

To define the variable, open Menu Project > Properties > Variables and define a new variable (called e.g. fotopath), using an expression like this one, replacing [windows_path] and [android_path] with the absolute path:

if (@qgis_os_name = 'windows', '[windows_path]','[android_path]')

Then get the path calling the variable: eval(@fotopath)

enter image description here

6
  • Variables definitely look like the right way to go with this, but I haven't managed to accomplish it because a) none of the places to enter paths seem to have an expression editor to pick the right variable on the basis of the value of @qgis_os_name (or some other way to tell whether QGis or QField is running) b) none of them appear to do anything anyway, for reasons I haven't managed to work out (cf the sub-question) (except sometimes, cause a python crash). Syntax like ../projectphotos especially does not appear to put photos in a sister directory to the default. Commented Dec 5, 2022 at 1:39
  • See updated answer. You can get the right variable name for @qgis_os_name in any expression string builder dialog anywhere in qgis, look for the correct syntax there and than copy/paste the expression to the variable definition.
    – Babel
    Commented Dec 5, 2022 at 8:49
  • Still not getting anywhere, perhaps due to an error somewhere, or not knowing where to put the folder name. In project variables I have 'if ( @qgis_os_name = 'windows','d:\QFieldPhotos\','/storage/emulated/0/Android/data/ch.opengis.qfield/data/files/Photos/')' (no quotes around the whole thing typed into the box, they appear in the display. I've also tried putting eval(@photopath) i 'Attachment Directories' in the QField section of Project Configuration, and am about to add a pic of what I have in the widget type window to the original question. Commented Dec 6, 2022 at 0:07
  • Use forward backslashes / not backward backslashes `\`. If it doesn't work, type the whole path by hand where you use it. In this case you see if it works at all. Not sure about android, storage access is more restricted there, maybe ask a separate question about this. If it doesn't work for windows, provide a sample project for testing.
    – Babel
    Commented Dec 6, 2022 at 7:19
  • Does it work on windows?
    – Babel
    Commented Dec 6, 2022 at 7:22
0

The answer appears to be that this is impossible: a QField project can't do anything with folders outside of the project: https://github.com/opengisch/QField/discussions/3726, even if they are in the QField app folder.

An way to not copy large numbers of photos every time you package or synchronize that does seem to work is to use a sophisticated file synching app such as one of the Autosync ones or Filesync, although it would be necessary to be careful with these in order to not clobber data.

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.