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 new to the Quantum Plugin development and wonder if there is more information about the following.

I have added a shape file and am (off course) able to select a point from this shape file. In the shape file I have stored the location (x,y) and an id.

Now I would like to be able to select a point in this layer and then my plugin should be able to recognize the id of the point, look up a database and display a graphical representation of the data in the database.

So what I am looking for is this,

  • how do I get the information of a selected point to my plugin
  • is it possible that my plugin overwrites the default information dialog (so the plugin pops up instead of the normal dialog)
  • is there perhaps a plugin that already shows such behaviour and I can learn from (haven't found one so far)

Thanks (very much) in advance! Rob

share|improve this question
    
I found the answer (thanks to the advice of Giovanni) in the following excellent workshop; qgisworkshop.org/html/workshop/… Works like a charm! –  BreinBaas Nov 13 '12 at 14:28
add comment

1 Answer 1

for the first question (obtain informations from the selected feature) I suggest you to connect the layer's selectionChanged() event to a method of your plugin:

self.mylayer = qgis.utils.iface.mapCanvas().currentLayer() #Obtain a raference to the layer you're interested in
QObject.connect(mylayer,SIGNAL('selectionChanged()'),<yuormethod>)

In you could code something like in this snippet.

For the information dialog, you can write your own QDialog, and show up whatever you want. The simplest workflow would be:

  1. The user selects the feature
  2. and clicks on your "tool", which will extracts the informations from the selected feature and popup your dialog.

Obviously you have to take care that the layer isn't deleted, the selected layer isn't changed, etc. between point 1 and point 2.

Otherwise, write your own "select/identify" maptool, subclassying QgsMapTool or QgsMapToolEmitPoint

giovanni

PS: read carefully the PyQgis Cookbook ;)

share|improve this answer
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.