I use to create several projects very similar everyday.

For every project, I always do very repetitive task:

  1. create and style vector layers (road, roof, buildings) with same style and fields attributes
  2. create map themes using sames layers name
  3. organize the layers's order
  4. save my layer at the root folder of my QGIS file project.

Before automatize these tasks in PyQGIS, I would like to know the different approaches I could use.

My firsts ideas was to:

  • 1rst idea: create GeoPackage project with all layers, style and themes empty (without any entity). Import the project and save as in a new GeoPackage at the new location.


  • 2cnd idea: save style in .qml then create layers in a new project in PyQGIS then Organize layers in PyQGIS then create them in PyQGIS

In my opinion this kind of need should be common but I'm not sure which approach should I use in order to automatize this kind of workflow.

  • 2
    It depends of your need, but a .qgs is also a text file and if you know what you are doing you can even do search and replace in a kind of ".qgs template" and it will create projects as you required. Or you can work with a preset of folder and just moving your .qgs with relative path setting can make you project work ... Oct 25, 2021 at 7:27
  • 1
    I'm not sure to understand the 1rst approach you mentioned. About the second approach, if I understand well, you suggested me to dupplicate all my folders/files in a new location, and working into my QGIS project with relativ path in order to match the new location with the dupplicate files ?
    – zlikotp
    Oct 25, 2021 at 7:33
  • 2
    I don't know how your process work. It is just that if you have the same datasource everytime you can organize your sources in subfolders always the same way. save your .qgs once with relative setting. copy pasta your .qgs in the same data organisation, organize your data the same way, open the .qgs, and your new dataset will be in same "project" i.e : same layerstyle, same name of layer and order, but not the same source. Oct 25, 2021 at 7:40
  • 1
    try to open a .qgs with notepad or whatever text editor you have and you will understand ! =) Oct 25, 2021 at 7:42
  • 1
    Yes it's true. but what if you only use relative path to your .qgs and have a layer in subdirectory data\roads\roads.shp. and then in the same data organisation you copy paste at the root of another folder stricly same organisation (data\roads\roads.shp) your qgs. Assuming it's another roads.shp but for a different place, however same datastructure, then the .qgs will use this layer the same way it used the previous one .... NB : it is a good idea to use Pyqgis and script your process. I am just saying , maybe you don't need code. chose what suits your needs (I don't know them) Oct 25, 2021 at 10:56


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.