Bug report #15656
Loading QLR file with relative path does not work correctly
|Affected QGIS version:||2.18.14||Regression?:||No|
|Operating System:||Easy fix?:||No|
|Pull Request or Patch supplied:||Yes||Resolution:|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||23579|
I have some troubles loading QLR files with relative path. The path in the QLR is relative to the folder where the QLR file was saved which is good but it seems QGIS considers the path relative to the folder where the QGS project is saved.
For examle when I try to load a QLR in:
- a new, blank and non saved project > it works
- a QGS project saved in the same folder than the QLR file > it works
- a QGS project saved in a different folder than the QLR file > it does not works
[PATCH] [BUGFIX] Load layer from definition does not use qlr as relative path
Fixes #15656 Loading QLR file with relative path does not work correctly
#1 Updated by Tudor Bărăscu almost 5 years ago
You can choose between relative and absolute paths.
As you observed, QGIS considers the relative paths to the qgs project.
IMHO qlr is a definition of a layer to be used in the project. So, the datasource should be relative to the project and NOT to the qlr (which just defines the path to the datasource from the project perspective).
Are you saying that you're loading in a project a qlr file and it works but after saving the project (without loading the qlr file afterwards) it doesn't work anymore?
#2 Updated by Dominique Lyszczarz almost 5 years ago
Actually when saving a QLR the datasource path is relative to QLR destination folder, not the QGS one.
It seems this behaviour was fixed in #10858
But on another hand when QGIS load a QLR it search the datasource with a path relative to the folder where the qgs is saved.
This inconsistency causes lot of troubles.
For example if I have a shapefile in the folder foo/data and a qgs project in the folder foo/qgs, load the shp and save a new QLR to foo/myqlr.qlr then just trying to reopen this QLR and it does not find the datasource (there is no error message but the layer entry in the TOC is empty)
The path in the QLR is ./data/shapefile.shp which is correct (== foo/data/shapefile.shp) but I suspect QGIS search the source at foo/qgs/data/shapefile.shp. If I just resave my project to /foo/myproject.qgs or if I change the path in the QLR to ../data/shapefile.shp, then I can load correctly my QLR file.
#3 Updated by Juan Manuel Perez over 4 years ago
I agree with Dominique. We hava also stumbled into some problems caused by that inconsistency he points out:
"When saving a QLR the datasource path is relative to QLR destination folder, not the QGS one. But, on another hand, when QGIS load a QLR it searchs the datasource with a path relative to the folder where the QGS is saved"
If this behaviour is to remain as it is now, then maybe it could be fair if we could have a warning telling the user that loading the generated QLR will fail unless moved next to the QGS file.