|
| 1 | +# How to Set Photo Names Format |
| 2 | +<SinceBadge type="Plugin" version="2023.2.0" /> <SinceBadge type="App" version="v2.2.0" /> |
| 3 | + |
| 4 | +[[toc]] |
| 5 | + |
| 6 | +Names of the photos that are captured in the field using <MobileAppName /> can be customised. The name format can be set in QGIS with <QGISPluginName />. |
| 7 | + |
| 8 | +To use this option, make sure that the [photo widget](../../layer/settingup_forms_photo/#attachment-widget-in-qgis) of the fields you use for taking pictures is set up correctly, i.e. using the attachment widget, storing relative paths and, if needed, with a [custom folder](../../layer/settingup_forms_photo/#how-to-set-up-a-custom-folder-for-storing-photos) for storing photos. |
| 9 | + |
| 10 | +To set up custom photo names: |
| 11 | +1. Open your <MainPlatformNameLink /> project in QGIS and navigate to **Project Properties** |
| 12 | +  |
| 13 | + |
| 14 | +2. In the **Mergin Maps** tab, you can see the list of layers and their fields with correctly configured photo attachment widgets. |
| 15 | + |
| 16 | + Select a layer from the list and click on the **Expression builder** icon. |
| 17 | +  |
| 18 | + |
| 19 | +3. In the **Expression Dialog** window, enter the expression that should be used as the photo's name. Please, keep in mind [basic recommendations](#best-practice-for-photo-name-expressions) to make sure the naming works as intended. |
| 20 | + |
| 21 | + Here we use a combination of the layer's name, <MainPlatformName /> username and current timestamp (other examples ale listed [below](#examples-of-photo-names-expressions)): |
| 22 | + ` @layer_name + '-' + @mergin_username + '-' + format_date(now(),'yyMMddhhmmss')` |
| 23 | + |
| 24 | + Example result is displayed in the **Preview**: `hedges-sarah-230707194052` |
| 25 | + |
| 26 | +  |
| 27 | + |
| 28 | + Click **OK** to confirm the expression. |
| 29 | + |
| 30 | +4. Set up the photo name format for other fields and layers. |
| 31 | + |
| 32 | + The **Preview** in **Mergin Maps** tab includes the [custom folder for photos](../../layer/settingup_forms_photo/#how-to-set-up-a-custom-folder-for-storing-photos), if you have set it up. Otherwise you will see only the sample name of a photo. |
| 33 | + |
| 34 | +  |
| 35 | +  |
| 36 | + |
| 37 | +### Best practice for photo name expressions |
| 38 | +There are some tips to keep in mind when creating the expression for your photo name: |
| 39 | + |
| 40 | +:white_check_mark: **Each photo needs to have a unique name** to avoid issues during synchronisation and ensure that photos and features are linked correctly. |
| 41 | + |
| 42 | +Therefore, we recommend using combinations of variables that will ensure that there would not be multiple photos with the same name, such as the current date and time `now()`, <MainPlatformName /> username `@mergin_username`, layer name `@layer_name` or a field value. |
| 43 | + |
| 44 | +:white_check_mark: The file extension (`.jpg`) is added automatically. |
| 45 | + |
| 46 | +:white_check_mark: When using a field value in the expression, make sure that it is a field that will be filled out during the survey, e.g. by using [constraints](../../layer/settingup_forms_settings/#constraints). If the field is empty, the expression won't work! |
| 47 | + |
| 48 | +:white_check_mark: If you want to use a [numeric field](../../layer/settingup_forms/#numbers) or other non-text fields in your expression, you need to convert it to a string first using the `to_string()` function |
| 49 | + |
| 50 | +:no_entry_sign: The expression is evaluated with the **current** field values. The name of the photo will stay the same even if you change the value of the field later. |
| 51 | + |
| 52 | +:no_entry_sign: The setup needs to be saved and synchronised. Only photos that are taken after synchronisation will have the name defined by the expressions. Existing photos will keep their original names. |
| 53 | + |
| 54 | +In general, it is useful to use some of these variables: |
| 55 | +- Current timestamp `now()` is a good starting point to ensure uniqueness of the name of the photo. |
| 56 | + |
| 57 | + It can be variously reformatted using the `format_date()` function. See <QGISHelp ver="latest" link="/user_manual/expressions/functions_list.html#format-date" text="See QGIS User manual" /> for more details. |
| 58 | + |
| 59 | +- When working in a team, consider using <MainPlatformName /> username `@mergin_username`. |
| 60 | + |
| 61 | + Even if multiple team members capture a photo at the same time, the name will be different. Also, it makes it easy to sort photos based on who took them. |
| 62 | + |
| 63 | +- Layer name `@layer_name` or a field value. |
| 64 | + |
| 65 | + Depending on the layers in your project and their fields, it can help create a unique photo name when taking multiple pictures in a row. It can also help to make it easier to browse pictures in your <MainPlatformNameLink /> project. |
| 66 | + |
| 67 | + |
| 68 | +### Examples of photo names expressions |
| 69 | +Here are some example expressions that can be used or modified to fit your needs: |
| 70 | + |
| 71 | +- Expression: ` @layer_name + '-' + @mergin_username + '-' + format_date(now(),'yyMMddhhmmss')` |
| 72 | + - Preview: `hedges-sarah-230707154052.jpg` |
| 73 | + - Description: This is a combination of the name of a layer (`hedges`), <MainPlatformName /> username (`sarah`) and reformatted timestamp that starts with the year and ends with seconds. |
| 74 | + |
| 75 | +- Expression: ` "species" + format_date( now(),'-yyyyMMdd-hhmmss')` |
| 76 | + - Preview: `Silver birch-20230707-154052.jpg` |
| 77 | + - Description: `Silver birch` is a value of the `species` field. Current timestamp is reformatted with added hyphens to separate the date and time. |
| 78 | + |
| 79 | +- Expression: `'photo-' + format_date( now(),'ssmmhhddMMyy')` |
| 80 | + - Preview: `photo-520415070723.jpg` |
| 81 | + - Description: A string can be added to the photo name (here: `photo-`). The order of the timestamp is reversed (compared to the previous examples), starting from seconds. |
| 82 | + |
| 83 | +- Expression: `@layer_name + ' ' + to_string("house-number") + ' at ' + format_date( now(),'ssmmhh') + ' on '+ format_date( now(),'ddMMyy')` |
| 84 | + - Preview: `house 41 at 520415 on 070723.jpg` |
| 85 | + - Description: Here we use the name of a layer (`house`), followed by a string adding space. A numeric field (`house-number`) is converted to a string. The timestamp is divided to display the time and date separately, with added strings `at` and `on` to make the photo name more readable. |
0 commit comments