[QGIS-Developer] QGIS standalone script examples

Richard Duivenvoorde rdmailings at duif.net
Mon May 24 03:46:17 PDT 2021


On 5/24/21 9:20 AM, Paul Wittle wrote:
...

> However as I say; the resulting project file is significantly smaller than the one that was read so it must be deleting things it shouldn't even be modifying; I assume because the bridge bit is not being used and because it is running standalone.
> 
> Is that enough information?

Yes :-)
That is a very interesting excercise!

Thought to try to create a minimal example script:

- created a project with a small map from nl.gpkg in it
- created a qgs file from that called template.qgs
- created the script (at first without the 'app' parts (which also worked) which opens/loads the template.qgs, loads another (river) layer and places that in a group (groupname) in the layer tree, and then writes out to another testoutput.qgs project file.

And well, that just worked, I can open the testoutput project and it 

See https://duif.net/standalone_save.zip for you to try/test (as I do this on Debian, did not test it on Windows). Both scripts/data/qgs files are in it.

Off course (for others) you need to have all your paths to libs/dll's ok and you have to set the right prefix path in the script.
And maybe change some ./ to .\ on windows?

If I look at the output qgs, indeed the canvas-part is missing, but... QGIS opens it just fine and both layers are also visible/valid
So I do not think the 'shrinking' of the project is the crux of the invalid layers.

Also the 'bridge' part is missing (with me), for what exactly was that needed? Because (I think(!)), that is if you write a script, and you want to sync the (off sight/background) layertree to the (visible) canvas (which we do not have), so I think it is not needed?

Ok, hoping my example is of any help, thanks for the excercise :-)

Regards,

Richard Duivenvoorde






More information about the QGIS-Developer mailing list