In this recipe, you'll learn how to add standard map navigation tools to a standalone map canvas. Creating the simplest possible interactive application provides a framework to begin building specialized geospatial applications using QGIS as a library.
Download the following zipped shapefile and extract it to your qgis_data
directory into a folder named ms
from https://geospatialpython.googlecode.com/files/Mississippi.zip.
We will walk through the steps required to create a map canvas, add a layer to it, and then add some tools to zoom and pan the map, as follows:
First, because we are working outside the QGIS Python interpreter, we need to import some QGIS and Qt libraries:
from qgis.gui import * from qgis.core import * from PyQt4.QtGui import * from PyQt4.QtCore import SIGNAL, Qt import sys, os
Then, we must set the location of our main QGIS application directory. This setting is platform-dependent:
# OSX: QgsApplication.setPrefixPath...