Saving a map to a project
Saving a project automatically can be useful for auto save features, or as part of a process to auto-generate projects from dynamically updated data. In this recipe, we'll save a QGIS project to a .qgs
project file.
Getting ready
You will need to download the following zipped shapefile and extract it to your qgis_data
directory in a subdirectory named ms
:
https://github.com/GeospatialPython/Learn/raw/master/Mississippi.zip
How to do it...
We will create a simple QGIS project by loading a shapefile layer, then we'll access the project object, and save the map project to a file, as follows:
- First, we need the Qt core library in the QGIS Python console:
from PyQt4.QtCore import *
- Next, we load the shapefile and add it to the map:
lyr = QgsVectorLayer("/qgis_data/ms/mississippi.shp", "Mississippi", "ogr") reg = QgsMapLayerRegistry.instance() reg.addMapLayer(lyr)
- Then...