[QGIS-Developer] QGIS standalone script examples

Richard Duivenvoorde rdmailings at duif.net
Sun May 23 12:31:31 PDT 2021


Hi Paul,

Can you come up with a little info about your actual use-case? Because maybe people then have some alternative ideas. QGIS-Application/Canvas off course does a lot of extra stuff when you load data (like for example using some default crs or styling etc etc...) not sure if you would want to redo that all in your scripts (IF it would be doable at all).

But maybe we could come up with another solution? (like maybe create 'qlr(?)' QGIS Layer files, or projects which point to other (small) projects (a project can be part of another project).
Or maybe you could re-use some excisting project by using some naming scheme in your data or so?

Regards,

Richard Duivenvoorde

On 5/23/21 12:59 PM, Paul Wittle wrote:
> 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 <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
> 
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 



More information about the QGIS-Developer mailing list