# How to Set Photo Names Format

since QGIS plugin 2023.2.0 since Mobile app v2.2.0

Names of the photos that are captured in the field using Mergin Maps mobile app can be customised. The name format can be set in QGIS with Mergin Maps QGIS plugin.

To use this option, make sure that the photo widget 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 for storing photos.

To set up custom photo names:

  1. Open your Mergin Maps project in QGIS and navigate to Project Properties
    QGIS Project Properties

  2. In the Mergin Maps tab, you can see the list of layers and their fields with correctly configured photo attachment widgets.

    Select a layer from the list and click on the Expression builder icon.
    Mergin Maps QGIS Plugin Custom photo name setup

  3. In the Expression Dialog window, enter the expression that should be used as the photo's name. Please, keep in mind basic recommendations to make sure the naming works as intended.

    Here we use a combination of the layer's name, Mergin Maps username and current timestamp (other examples ale listed below):
    @layer_name + '-' + @mergin_username + '-' + format_date(now(),'yyMMddhhmmss')

    Example result is displayed in the Preview: hedges-sarah-230707194052

    QGIS Expression for custom photo name

    Click OK to confirm the expression.

  4. Set up the photo name format for other fields and layers.

    The Preview in Mergin Maps tab includes the custom folder for photos, if you have set it up. Otherwise you will see only the sample name of a photo.

    Mergin Maps QGIS Plugin photo name setup with custom folder
    Mergin Maps QGIS Plugin Custom photo name setup without custom folder

# Best practice for photo name expressions

There are some tips to keep in mind when creating the expression for your photo name:

Each photo needs to have a unique name to avoid issues during synchronisation and ensure that photos and features are linked correctly.

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(), Mergin Maps username @mergin_username, layer name @layer_name or a field value.

✅ The file extension (.jpg) is added automatically.

✅ 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. If the field is empty, the expression won't work!

✅ If you want to use a numeric field or other non-text fields in your expression, you need to convert it to a string first using the to_string() function

🚫 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.

🚫 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.

In general, it is useful to use some of these variables:

  • Current timestamp now() is a good starting point to ensure uniqueness of the name of the photo.

    It can be variously reformatted using the format_date() function. See QGIS Documentation See QGIS User manual (opens new window) for more details.

  • When working in a team, consider using Mergin Maps username @mergin_username.

    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.

  • Layer name @layer_name or a field value.

    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 Mergin Maps project.

# Examples of photo names expressions

Here are some example expressions that can be used or modified to fit your needs:

  • Expression: @layer_name + '-' + @mergin_username + '-' + format_date(now(),'yyMMddhhmmss')

    • Preview: hedges-sarah-230707154052.jpg
    • Description: This is a combination of the name of a layer (hedges), Mergin Maps username (sarah) and reformatted timestamp that starts with the year and ends with seconds.
  • Expression: "species" + format_date( now(),'-yyyyMMdd-hhmmss')

    • Preview: Silver birch-20230707-154052.jpg
    • Description: Silver birch is a value of the species field. Current timestamp is reformatted with added hyphens to separate the date and time.
  • Expression: 'photo-' + format_date( now(),'ssmmhhddMMyy')

    • Preview: photo-520415070723.jpg
    • 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.
  • Expression: @layer_name + ' ' + to_string("house-number") + ' at ' + format_date( now(),'ssmmhh') + ' on '+ format_date( now(),'ddMMyy')

    • Preview: house 41 at 520415 on 070723.jpg
    • 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.