[QGIS-Developer] QGIS standalone script examples

Paul Wittle paul.wittle at dorsetcouncil.gov.uk
Sun May 23 03:59:37 PDT 2021


Hi folks,

I’m trying to do a simple script to open an existing project, add a layer and then save the result but finding it hard to piece together the information I can find online.

I’ve found various posts suggesting that you need to connect up the canvas or all the GUI information gets lost when you do a project.write() command but for some reason I can only find answers that contain snippets which usually seem to reference iface or canvas without showing how to initiate those in a standalone way.

Particularly, if you look at https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/loadproject.html you have a note about needing to set a bridge but that references canvas which if you copy/paste as per the details in that section alone will of course result in a ‘canvas undefined’ error.

Is there a simple full example anywhere that shows how you can open a project file using a standalone python script, add one layer and save it without losing half the information in the project file?

My best effort so far added the layer but resulted in existing layers being invalid when I opened the project in QGIS and my “improved” version…at the moment…seems to be almost halving the size of the project so I assume it is still deleting all the canvas information. Any hints would be appreciated 😊

Thanks
Paul
This e-mail and any files transmitted with it are intended solely for the use of the individual or entity to whom they are addressed. It may contain unclassified but sensitive or protectively marked material and should be handled accordingly. Unless you are the named addressee (or authorised to receive it for the addressee) you may not copy or use it, or disclose it to anyone else. If you have received this transmission in error please notify the sender immediately. All traffic may be subject to recording and/or monitoring in accordance with relevant legislation. Any views expressed in this message are those of the individual sender, except where the sender specifies and with authority, states them to be the views of Dorset Council. Dorset Council does not accept service of documents by fax or other electronic means. Virus checking: Whilst all reasonable steps have been taken to ensure that this electronic communication and its attachments whether encoded, encrypted or otherwise supplied are free from computer viruses, Dorset Council accepts no liability in respect of any loss, cost, damage or expense suffered as a result of accessing this message or any of its attachments. For information on how Dorset Council processes your information, please see www.dorsetcouncil.gov.uk/data-protection
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210523/617f907f/attachment.html>


More information about the QGIS-Developer mailing list