Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am using PyQGis API to create a custom application.

How do I allow users to select features with the mouse? Is there a mapTool for this? Surely with a product as powerful as QGis there must be.

Thanks in advance

share|improve this question
    
Have you looked at qgisworkshop.org/html/workshop/plugins_tutorial.html? It is a tutorial about building a Qgis plugin. –  GreyHippo Nov 9 '12 at 13:24
add comment

1 Answer

There is a class you can inherit from called QgsMapTool which you can override the mouse events to handle user actions.

Like so: https://github.com/NathanW2/qmap/blob/master/src/plugin/point_tool.py

You can find objects under the mouse click for example using code like this:

searchRadius = (QgsTolerance.toleranceInMapUnits( 5, layer, 
               self.canvas.mapRenderer(), QgsTolerance.Pixels))
        rect = QgsRectangle()
        rect.setXMinimum( point.x() - searchRadius );
        rect.setXMaximum( point.x() + searchRadius );
        rect.setYMinimum( point.y() - searchRadius );
        rect.setYMaximum( point.y() + searchRadius );

        self.band.reset()
        layer.select( layer.pendingAllAttributesList(), rect, True, True)    
        for feature in layer:
             # do something with the feature
share|improve this answer
    
Could you fix the link please? I think it's broken. –  underdark Mar 28 '13 at 16:52
add comment

Your Answer

 
discard

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.