Riverscapes / QRAVEPlugin

QGIS Plugin for viewing Riverscapes projects
0 stars 0 forks source link

Absolute paths in QRave QGZ are incorrect #84

Closed MattReimer closed 1 year ago

MattReimer commented 1 year ago

Currently when you save a QGis project with QRave projects open, those QRave projects get stored inside that project file so that when you open it again you get the same projects opening.

Internally this is handled when you open a project:

https://github.com/Riverscapes/QRAVEPlugin/blob/master/src/dock_widget.py#L210-L211

but there's a problem. We're storing absolute paths. There are two reasons why this is a problem.

  1. .qgz projects cannot be shared between users.
  2. Imagine you have a folder with a .qgz file and a bunch of QRave projects. If you move this folder (for example from your c: drive onto your d: drive then this QGis project will load the layers but not the projects

We should not have the layers being stored with relative paths while the projects are stored with absolute paths.

The task here is to make sure the QGZ file contains relative paths so we don't end up with the following:

    <QRAVE>
      <enabled type="int">1</enabled>
      <qrave_projects type="QString">
[[
"VBET for HUC 17060304", 
"VBET for HUC 17060304", 
"c:\myawesomefolder/17060304/Valley_Bottom_Extraction_Tool_VBET-17060304 (2)/NEW/project.rs.xml"
]]
</qrave_projects>
    </QRAVE>
MattReimer commented 1 year ago

I think we should be able to solve this fairly easily by hooking into the project save and injecting the paths.

https://gis.stackexchange.com/questions/75221/qgis-action-adding-layers-using-relative-paths

QgsProject.instance().fileName() // gives you the project path.
MattReimer commented 1 year ago

There is a fix for this now. I need to test it on windows though before we commit to it.