2

I have created a QGIS 3.34 project in this directory: "C:/MyProject". Alongside with the QGIS project file there is a folder containing some georeferenced pictures I want to show on my QGIS project. Its directory would be: "C:/MyProject/MyPictures".

In the project, such images were imported by creating a geopackage saved in "C:/MyProject" as well. Then, I want to display such images when the cursor is placed over a certain point, like in the picture below:

enter image description here

For that, I double-clicked on my pictures layer, went to display and inserted the following HTML code:

<img src="file:///[% photo %]" width="375" height="250">,

where "[% photo %]" refers to the absolute path of each picture.

As long as the project is in "C:/MyProject", everything behaves correctly. However, my intention is to save such a project in more than one computer. When I copy the "MyProject" folder to another computer and run QGIS from it, I see that the pictures are gone:

enter image description here

I would like to link all those pictures to the project by making QGIS refer to them just by using a relative path like this: 'MyPictures/[filename]', but I don't know how to do this.

By writing the following code,

enter image description here

the image is not displayed yet. In this case, the subfolder where the pictures are is called "Camera_GeoTagged". I followed the steps that @eurojam provided, but my [% filename %] value refers just to the filename itself, without providing any extension, in this case '.jpg'. If I remove the '.jpg' characters from the HTML code I still get the same preview with the image not found.

Is there a way to import the georeferenced pictured to QGIS with a filename that clearly shows its extension?

1 Answer 1

6

you can put the images in a subfolder below your project and then you can refer to the images as a relative path...in the example below I have a field imagestoring the file name, which are located in a subfolder /photos. For the map tips I use HTML map tips with the following form:

<img src="file:///photos/[% image %]"  width="200"></img>

enter image description here

enter image description here

7
  • Thanks for your answer. I've applied your method but the fact that my filenames don't contain the image extension doesn't let me do that. So I can't see the pictures appear yet. I've edited my post by introducing these facts. Do you know how could I proceed now?
    – user9867
    Feb 21 at 16:21
  • Your expression should work, I've tried it the same way like you without any problems...: <img src="file:///photos/[% filename %].jpg" width="200"></img>
    – eurojam
    Feb 22 at 16:10
  • That's strange... Perhaps it's a settings issue. Do you think it has to do with the Attribute Table? Besides, I imported the images by going to the Processing Toolbox panel on the right hand side > Vector creation > Import geotagged pictures. Is this the way you would recommend me to import them? Perhaps that's causing the error.
    – user9867
    Feb 23 at 8:32
  • I did it the same way, then I added an new textfield "image" with the fieldcalaculator: "filename" || '.jpg' and used this one in the expression above...
    – eurojam
    Feb 23 at 11:40
  • I also did that but still getting the same error. I set the new textfield as string, but it didn't work. Have you got any ideas why it might be not working in my case?
    – user9867
    Feb 26 at 9:34

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.