Navigating to a map bookmark
Map bookmarks store important locations on a map, so you can quickly find them later. You can programmatically navigate to bookmarks using the Python sqlite3
library in order to access the bookmarks database table in the QGIS user database and then use the PyQGIS canvas API.
Getting ready
We will use a census tract layer to test out the bookmark navigation. You can download the zipped shapefile from https://geospatialpython.googlecode.com/files/GIS_CensusTract.zip.
Manually load this layer into QGIS after extracting it from the ZIP file. Also, make sure that you have completed the previous recipe, Creating a map bookmark. You will need a bookmark named BSL for an area of interest in this shapefile.
How to do it...
We will retrieve a bookmark from the QGIS user database and then set the map's extents to this bookmark. To do this, perform the following steps:
First, import the Python
sqlite3
library:import sqlite3
Next, get the location of the user database from the...