O'Reilly logo

Mastering QGIS by GISP Dr. John Van Hoesen, GISP Dr. Richard Smith Jr., GISP Kurt Menke, Dr. Luigi Pirelli

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Interacting with the map canvas

A plugin will commonly interact with the map canvas to get some useful information. This information could be, for example, point coordinates or features identified by these coordinates. We can use them to draw geometry entities like points, lines, or polygons.

Getting the map canvas

The QgsMapCanvas class is the class that represents a QGIS canvas. There can be different canvas instances, but the main canvas instance can be referenced with the following code snippet:

mapCanvas = iface.mapCanvas()

The QgsMapCanvas class generates some useful events to support location-based plugins. For example, xyCoordinates() sends point locations based on canvas coordinates and the keyPressed() event allows us to know which mouse ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required