7

Objective: I have point layers with attributes that contain paths to external files (Visio, AutoCAD dwg...). I want to put them all in one folder together with the project file, compress the folder into a ZIP file and send it to my colleagues for review. When my colleague de-compress the ZIP file, they would be able to open those files with simple actions like the posts linked below.

My observation: what I want to accomplish is very similar to those discussed in Adding a hotlink to an attribute field in QGIS and How to add links to PDFs in a Shapefile? with one difference: when the ZIP file is decompressed, the absolute path to referenced files will be different. But I think that RELATIVE PATHS to the project file will be the same, so why not use this?

The problem is: that I can not find a way to open external files with relative paths inside QGIS.

Any idea how to solve this problem?

4 Answers 4

4

There is another solution for portable project with relative path for any attachment. With this solution you can open any document using system default browser/viewer.

  • Create new Action
  • Select type - python
  • Paste code bellow to the Action text area
  • Replace the_name_of_culumn_with_relative_path with the name of your column
import subprocess, os
import os.path; 
import subprocess;
from PyQt4.QtGui import *;
filerelpath = "[% <the_name_of_culumn_with_relative_path> %]"; 
if (filerelpath is not None and len(filerelpath) > 0):
  projectpath = qgis.core.QgsProject.instance().fileName(); 
  path = os.path.dirname(str(projectpath)) ; 
  file = os.path.abspath(os.path.join(path, filerelpath)); 
  if sys.platform.startswith('darwin'):
      subprocess.call(('open', file));
  elif os.name == 'nt':
      os.startfile(file);
  elif os.name == 'posix':
      subprocess.call(('xdg-open', file));
else:
  msg = QMessageBox()
  msg.setText('No attachment');
  msg.show();

enter image description here

3

You could try the eVis plugin for QGIS

http://biodiversityinformatics.amnh.org/open_source/evis/documentation.php#d0e390

0
3

Thanks to Rayner's answer, I can do what I want now - with some things to remember:

  1. The relative path stored as attribute in data table should use forward slash (/), like: '/subfolder/file.ext' (without apostrophes) because my Linux Mint system won't work with back slash (\) while Windows XP can work with both styles.
  2. The base path specified in eVis' Options tab should use your operating system's convention, that is: 'C:\path\to\project\folder\' (without apostrophes) on Windows and '/home/user/path/' (without apostrophes) on Linux.

Otherwise I will receive an alert that the file could not be found.

2

Add to open action (it works only from QGIS 3 versions):

[% @project_folder %][% "relative_photo_path_column_name" %]

(solution from here: https://gist.github.com/colemanm/5406487)

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.