4

I'm developing a custom GIS application using the 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 the 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.

Matt
19.4k4 gold badges25 silver badges64 bronze badges
asked Oct 9, 2012 at 9:59
1
  • Please keep to the site format of only ONE question per thread. I'll remove the second one, please repost it. Commented Oct 12, 2012 at 10:35

1 Answer 1

6

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 )

Toolbar

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.

answered Apr 22, 2013 at 14:11
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.