How to load a QGIS project in python

Posted by: Gavin Fleming | in QGIS | 2 years, 6 months ago | Comments

Today in a project we are working on we wanted to load a QGIS project. It takes  surprisingly few lines of code to make a small standalone application that loads a project and then shows it as a map in a window like this:

 

Here is the code I wrote to produce this:

The main bit of magic is the QgsLayerTreeMapCanvasBridge class which will convert your project into a layer tree so that the layers appear in the canvas. If you ever need to make a standalone python application with a nice map in it, consider using the QGIS API to do it!

Current rating: 3.0

Comments

Template by Blacktie Mezzanine theme by CodingHouse