Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm developing a custom GIS application using PyQgis API.

How can I let the user select features on the map using Maptools? I would like to replicate the select feature there in Qgis to make the selection on click of a button. My understanding is to use layer.selectedFeatures() function , but I am not sure of how to add the Selection Maptool to the mapcanvas and toolbar.

share|improve this question
Please keep to the site format of only ONE question per thread. I'll remove the second one, please repost it. – underdark Oct 12 '12 at 10:35

The selection map tools are not part of the qgis libs. You therefore have to reimplement the behavior if you are writing a custom app.

Maptool implementation

You will have to subclass qgis.gui.QgsMapTool and implement the canvasPressEvent, canvasMoveEvent and then modify the layer selection according to this.

You can have a look at the source files of the existing selection maptools ( e.g. qgsmaptoolselectpolygon.cpp ). They are C++ code, but pretty simple and should explain the concept.

Add to the mapcanvas

You will have to call the method setMapTool of your QgsMapCanvas instance and pass an instance of your own selection map tool as parameter.

myMapcanvas.setMapTool( mySelectionTool )


You have to create an action and connect its triggered signal to a method (slot) where you will set the map tool as outlined in the last paragraph.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.