6

I reorganized my shapefiles folders. Now the layer file paths are broken. I have tried the solutions shown in the QGIS User guide (chapter 6.2), but:

  • I don't want to process my layers individually since there are far too many of them.
  • The "Auto-Find" in the "Handle Unavailable Layers" dialogue, also the scan in the "Repair Data Source" tool ("QGIS scans through all other broken paths and tries to auto-fix those that have the same broken file path") don't work properly. It makes some mistakes, and then it's a total mess to fix it.

I have a list of the before/after paths, which I could use in a "replace layers file path" tool, which would be the simplest way. But it seems not to exist in QGIS, does it? Or is there another tool for that?

I have also seen that post, but my python skills don't allow me to generalise it to solve my problem. Do you know a code that allows me to batch-replace the path on all concerned layers? Like X to X', Y to Y', Z to Z' etc.

Taras
35.8k5 gold badges77 silver badges152 bronze badges
asked Mar 14, 2023 at 14:35
2
  • I suggest you load your layers anew if you don't want to fix them manually. Commented Mar 14, 2023 at 14:45
  • It's a very big map, that would take me hours ; and i have serveral maps to repair. Therefore the Babel's solution is better for my case. Thanks anyway Commented Mar 15, 2023 at 15:06

2 Answers 2

6

Save your project as QGIS files (.qgs), not the default (zipped) .qgz file - or unzip the .qgz project file. Then you're able to open the project in a text editor in a human-readable format. There, you can find and replace the paths to the broken layers.

You have to change the path/layer name in two places. Look for:

  1. Layer tree, looking something like this: <layer-tree-layer [...] source="./layer_1.gpkg|layername=points_start">

  2. Datasource, looking something like this: <datasource>./layer_1.gpkg|layername=line</datasource>

In both cases, the name of the file is layer_1.gpkg, and the path is relative - the file is in the same folder as the project file: ./. Change both instances accordingly.

Taras
35.8k5 gold badges77 silver badges152 bronze badges
answered Mar 14, 2023 at 14:58
1
  • 3
    It works well, thanks ! I just had to understand the way the relative paths are anotated, which is quite simple: each descent of a level in the tree structure is is indicated by "../". With the use of find+replace, I did'nt have to pay attentoin the two distinct places mentioned above. Commented Mar 15, 2023 at 14:59
0

Install the changeDataSource plugin from the repository. Enter values in the Find and Replace fields then select the Replace button to bulk update layer file paths. Any affected strings turn yellow. Then select Apply and they'll turn green if the new connection is valid or red if it isn't. Alternatively, you can just type over/into the connection strings by double clicking them and then selecting Apply:enter image description here

answered May 16, 2023 at 10:49
1
  • 1
    We're looking for detailed Answers that not only suggest a solution, but explain why it should be used, and shows how it helps. Commented May 16, 2023 at 12:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.