I have about 600 folders with shapefiles always having the same filename per folder (which contain different data, of course). I've created one QGIS project file to open those shapefiles per folder always in the same way. I did this on one set of shapefiles, adjusted everything to my liking in QGIS and saved it. Afterwards in the code, I've changed the absolute path to those shapefiles to a relative path, and copied in every folder such a qgs-file.

Is it possible to make each project zoom to its extent on opening? Now, every project file I open zooms to the location of my initial "project", where I created the first project file.

I see this in the project file:

    <mapcanvas annotationsVisible="1" name="theMapCanvas">

or this:

    <maplayer autoRefreshTime="0" refreshOnNotifyMessage="" geometry="Line" readOnly="0" simplifyDrawingHints="1" autoRefreshEnabled="0" refreshOnNotifyEnabled="0" simplifyAlgorithm="0" labelsEnabled="0" minScale="1e+8" type="vector" simplifyDrawingTol="1" hasScaleBasedVisibilityFlag="0" simplifyLocal="1" maxScale="0" simplifyMaxScale="1">

And several other lines of code like it. Is it possible to make every project file automatically zoom to extents by changing something in the code? Or am I looking in the wrong place?

Edit: QGIS project is opened outside QGIS, on which QGIS starts. (I hope I said this correctly...)

  • I'd go with the map canvas part, since this only shows up once in the project file and I checked it for one of my projects. Problem is, I do not know, whether you can adjust these values automatically or have to open every project, zoom to the contents, save & exit.
    – Erik
    Nov 6, 2019 at 8:52
  • Erik, opening every individual projectfile (approx. 600) is just what I try to avoid. I've already tried to delete the lines <xmin>, <ymin> and so on, hoping QGis would take over. But that didn't do the trick. You see, I'm kind of swimming here, since I certainly don't have the knowledge.
    – Nico
    Nov 6, 2019 at 9:29

1 Answer 1


I would propose to use a macro for that. Go to project properties->macros and change the default code to:

from qgis.utils import iface
def openProject():

this will zoom to full extent after loading the project. You have to enable macros without asking (Settings->Options->general).

enter image description here

  • Seems that I wasn't complete in my question: I open the QGis-project outside of QGis, which triggers QGis to start of course. So, not from within QGis.
    – Nico
    Nov 6, 2019 at 9:24
  • You could probably put this into the QGIS project file. Just do it once inside of QGIS and save the project. Then copy the updated project file into all the folders.
    – csk
    Nov 6, 2019 at 20:03

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.