Absolute vs relative paths in QGIS projects

The choice between absolute and relative paths is a setting in QGIS projects that I wasn’t aware of until the beginning of 2024. At that time I got the course material from a QGIS workshop a co-worker used to teach and which mentioned this option. Since then I have started teaching the QGIS workshops for this company and of course “Absolute and relative paths” is now also part of my workshops.

So is this an important setting? Well, you can use QGIS perfectly well without knowing that this setting exists, but it’s good to know about it – as you will see below. This blog post explains what absolute and relative paths are and when you should use each.

What are paths?

When I teach QGIS workshops, I often notice that many people don’t know what paths are. So, a quick explanation is necessary:

A path is the location where a file is saved – where you can find it again if you ever need it.

On Windows, a path might look like:

C:\my_folder\my_subfolder\my_file.json 

On Linux, it could be:

/home/laptopuser/my_folder/my_subfolder/my_file.json

What is an absolute path?

An absolute path shows the full location of a file, including the drive, folders, subfolders, and the filename.

For example:

C:\my_folder\my_subfolder\my_file.json

No matter where you are on your drive, this path always points to the same file. Even if you move the QGIS project file where the path is stored, it will still refer to the file in that exact folder on the C drive.

What is a relative path?

A relative path shows a file’s location in relation to the project file’s location.

Relative paths don’t include the drive letter. Instead, they may start with symbols like ..\ or .. Let’s assume your QGIS project file is saved at:

  • ..\foldername\filename.gpkg → goes up one level, so the file is at C:\data\foldername\filename.gpkg
  • ..\..\foldername\filename.gpkg → goes up two levels, so the file is at C:\foldername\filename.gpkg
  • .\foldername\filename.gpkg → stays in the same folder, so the file is at C:\data\My_QGIS_projects\foldername\filename.gpkg
  • \foldername\filename.gpkg → starts from the root of the drive, so the file is at C:\foldername\filename.gpkg
  • foldername\filename.gpkg → behaves the same as .\foldername\filename.gpkg

QGIS generates these relative paths automatically when you add layers, so you rarely need to type them yourself. But understanding how they work will help you decide whether to use absolute or relative paths.

Where to find this setting?

The choice to use relative or absolute paths is made per project. This means the setting can be found in the project properties.

In the Properties you go to the General tab and there you will find the setting “Save Paths” where you can choose between Relative and Absolute.

Here, you can choose between Relative or Absolute. Once you select one option and click OK or Apply, QGIS will save the paths to your layers accordingly the next time you save the project.

Why is this choice important?

This setting matters when you move your QGIS project file and/or the data layers it uses. Depending on your workflow, either setting might be the better choice.

When to use absolute paths?

Use absolute paths when:

  • You move the project file only, but not the layers.

For example:

  • Your project file is at
    C:\data\My_QGIS_projects\My_Project.qgz
  • Your layers are at
    C:\data\My_QGIS_projects\layers\
  • You move only the project file to another drive, e.g.
    N:\projects\My_QGIS_projects\My_Project.qgz

Since the layers are still in the same place on the C drive, QGIS will still find them if you used absolute paths when you open the moved project file. With relative paths, it would fail.

When to use relative paths?

Use relative paths when:

  • You move the project file and its layers together.
  • You want to share a project with someone else and you mail the project and layers as a zip file.

Example:

  • Your project file is at
    C:\data\My_QGIS_projects\My_Project.qgz
  • Your layers are at
    C:\data\My_QGIS_projects\layers\
  • You move the whole My_QGIS_projects folder (including the project file and all layers) to another drive:
    N:\projects\My_QGIS_projects\

With relative paths, QGIS will still find the layers. With absolute paths, it would break because the drive letter and folder changed.

Another scenario: you zip your project and data and send it to a colleague. When they extract the folder anywhere on their system, QGIS will still resolve the paths correctly if you used relative paths.

Which one do you choose?

If you move both the project file and the layer files used in that project together (same folder structure), you should use relative paths.

If you move only the project file, but the layer files used in that project stay in the same place, you should use absolute paths.

If you move only your layer files, but not your project file, neither of the settings will give you a solution, and you will have to tell QGIS manually where the new layer files are.

When do I change this setting?

You don’t need to decide between relative or absolute paths when you first create your project. However, it’s important to check and adjust this setting before you move your project file or data layers. That way, you avoid broken links and missing data.

4 thoughts on “Absolute vs relative paths in QGIS projects”

  1. Hi,

    I am trying to figure out a way to set up some layers with relative paths and others with absolute paths. This setup allows me to use a .qgz file as a template that I can copy to multiple folders. I will also copy the layers that I want to update for each project, which will have relative paths. However, I would like some layers to have absolute paths, so I don’t have to copy them, as they will not be amended.

    This solution would save time and space on my PC, as multiple users could access the project files via OneDrive without needing to download the “static” layers for each project.

    Is there a way?
    Thank you in advance.

    Reply
  2. This doesn’t seem to work. When I try to reach a shapefile in a sub-folder;
    .\subfoldername\filename.shp
    or
    subfoldername\filename.shp

    Neither works, before or after reopening the .qgz. And if I use the “auto-find” option when opening the session the files are found one at a time, but paths get replaced with network paths, with “/” in stead of “\”:
    //name1/name2/subfoldername/filename.shp

    Reply

Leave a Comment