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://github.com/GeospatialPython/Learn/raw/master/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 ...

Get QGIS Python Programming Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.