Skip to content

Instantly share code, notes, and snippets.

@colemanm
Last active February 3, 2020 20:45
Show Gist options
  • Save colemanm/5406487 to your computer and use it in GitHub Desktop.
Save colemanm/5406487 to your computer and use it in GitHub Desktop.
Custom action to link to photos within a GIS feature class.

QGIS Open Image Custom Action

Use this guide to link a path name to a feature's photo in the attribute table.

This assumes you have a column in your data containing the full path to the image you'd like to open (in this example, a field called photo_path).

Create Action

  1. Right click feature class → Properties
  2. On Actions tab:
  • Type: Open
  • Name: Open Photo
  • Action: [% "photo_path" %] (select the field from the list and click "insert field")
  1. Add to action list

Open a Photo

With the info window for a feature open, right click the photo_path field and you'll see your custom "Open Photo" action at the bottom. Now photos can be opened with one click from the attribute table using the default system image viewer.

@Hornbydd
Copy link

Could you provide and example when the text field contains a relative path? For example how do you create an action that opens a photo when the text field is storing "media/img1234.jpg" (minus the quotes)?

@emmaebachman
Copy link

If you set it up the same way as they describe, and then copy/paste the project path directly in front of the relative path in the action code, then it will open the image.
C:\Users\...\[% "photo_path" %]
The only issue with this is that you'll have to change the URL in the action if you change the project path. There should be a way to access the project path from within the program, but I haven't been able to find that yet.

@jescott2
Copy link

For Windows and QGIS 3, try:
[% @project_folder %][% "photo_path" %]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment