Book Image

QGIS Python Programming Cookbook

Book Image

QGIS Python Programming Cookbook

Overview of this book

Table of Contents (16 chapters)
QGIS Python Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a map bookmark


Map bookmarks allow you to save a location on a map in QGIS, so you can quickly jump to the points you need to view repeatedly without manually panning and zooming the map. PyQGIS does not contain API commands to read, write, and zoom to bookmarks. Fortunately, QGIS stores the bookmarks in an SQLite database. Python has a built-in SQLite library that we can use to manipulate bookmarks using the database API.

Getting ready

You can download a census tract polygon shapefile to use with this recipe from https://geospatialpython.googlecode.com/files/GIS_CensusTract.zip.

Extract it to your qgis_data directory. We are going to create a bookmark that uses an area of interest within this shapefile, so you can manually load the bookmark in order to test it out.

How to do it...

We will access the QGIS configuration variables to get the path of the user database, which stores the bookmarks. Then, we'll connect to this database and execute a SQL query that inserts a bookmark. Finally...