Last active
April 3, 2019 14:53
-
-
Save timlinux/22935c16da4eda92762f to your computer and use it in GitHub Desktop.
Load and show a QGIS project in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
# A simple demonstration of how to load a QGIS project and then | |
# show it in a widget. | |
# This code is public domain, use if for any purpose you see fit. | |
# Tim Sutton 2015 | |
import os | |
from qgis.core import QgsProject | |
from qgis.gui import QgsMapCanvas, QgsLayerTreeMapCanvasBridge | |
from qgis.core.contextmanagers import qgisapp | |
from PyQt4.QtCore import QFileInfo | |
with qgisapp(): | |
project_path = os.path.dirname(__file__) + os.path.sep + 'test.qgs' | |
canvas = QgsMapCanvas(None) # will reparent it to widget via layout | |
# Load our project | |
bridge = QgsLayerTreeMapCanvasBridge( | |
QgsProject.instance().layerTreeRoot(), canvas) | |
QgsProject.instance().read(QFileInfo(project_path)) | |
canvas.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment