1

I have a layer of points and I associated a Python action to that layer which basically opens a url in the embedded QWebView.

This works well.

The issue I am facing is that if I zoom out and click on a region where several features are overlapping, the QWebView opens and reopens as many times as there are features stacked there.

Is there a way to prevent this? like:

  • Stop previous action when a new one is launched

or

  • Prevent the action to be ran for features that are not the first one visible
  • What would be the "first one visible" ? If some objects are overlapping in a layer i'm not sure you can define any "z-order" in the "objects stack" .... unless you have some useful additionnal information in your attribute table ? – snaileater May 3 '18 at 17:18
  • You know, when you use the select tool and you click on a region where several features are overlapping, the one on the top - i.e. the "visible" one, or the one that is rendered on the top of the others - is the only one to be selected. I'd like to run the action the same way, only once for the feature that is "on the top". – ClemRz May 3 '18 at 17:28
  • I fear "on the top" has no meaning here ... in Python u can write maptools where, using the right geographical operator (like "contains"), u could eventually discriminate your overlapping features by clicking on a given area ... but it depends on the complexity of your layer ... – snaileater May 3 '18 at 19:06
  • @snaileater I'm using the "Actions" environment to run the python script which means that I might not have the hand on what you mentioned. I believe that QGIS simply triggers the action for each elements that are where you click, and not only for the one "at the top" you know. Did I misunderstood your comment? Let me know and thanks for your interest. – ClemRz May 3 '18 at 19:13
  • I see in github code that the actions are ran for all the features that intersect with a 2-searchRadiusMU-square centered on the click location. "searchRadiusMU" means search radius in map units, it is derived from "searchRadiusMM" which can be changed in Settings > Options... > Map Tools > Identify > Search radius for identifying features and displaying map tips. The clicked coordinates are passed to the context: $clickx and $clicky, that might be a lead... – ClemRz May 3 '18 at 23:58
1

As I commented, $clickx and $clicky were a good start. Here is the code that allows to perform an action only on the "top-most" feature: https://gist.github.com/ClemRz/e08d856ca93502b8fa3f16ad531110a5

  • This is surely not the most elegant/efficient way to do so. If someone has a better way please let me know! – ClemRz May 4 '18 at 1:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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