Loading a map from a project
This recipe demonstrates how to load a project from a .qgs
XML file. Loading a project will set up the map and project settings for a previously saved project within QGIS.
Getting ready
You will need to complete the previous recipe, Saving a map to a project, so that you have a project named myProject.qgs
in your qgis_data
folder.
How to do it...
For this recipe, you need to set up a file object, set a resource path, and then read the file object that references the project file. To do this, you need to perform the following steps:
- First, we import the core
Qt
library for the file object:from PyQt4.QtCore import *
- Next, we initiate the file object with the path to the project file:
f = QFileInfo("/Users/joellawhead/qgis_data/myProject.qgs")
- Now, we access the project object:
p = QgsProject.instance()
- Then, we set the resource path for QGIS to find data and other files, in case the project was saved with relative paths instead of absolute paths:
p.readPath...