4

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">
    <units>meters</units>
    <extent>
      <xmin>57917.75605197192635387</xmin>
      <ymin>175589.96959768730448559</ymin>
      <xmax>66470.8240169670607429</xmax>
      <ymax>188067.17660002846969292</ymax>
    </extent>

or this:

    <projectlayers>
    <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">
      <extent>
        <xmin>58356.25057576912513468</xmin>
        <ymin>176062.54183909948915243</ymin>
        <xmax>66236.00066302371851634</xmax>
        <ymax>186876.7839431082829833</ymax>
      </extent>

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...)

2
  • 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

6

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():
    iface.zoomFull()

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

enter image description here

2
  • 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.