[Qgis-user] Action definition for features highlight in other layer.

Fernando M. Roxo da Motta petro at roxo.org
Thu Nov 12 15:01:34 PST 2015


On Thu, 12 Nov 2015 18:56:28 -0200, "Fernando M. Roxo da Motta"
<petro at roxo.org> wrote:

  Again answering myself hoping to be useful to someone.

  I was able to do what I wanted creating an action for the Src layer
with the code:


import processing
processing.runalg('qgis:selectbyexpression','RcvPoints','abs("XCoor"-[%"XCoor"%])<=3900
and abs("YCoor"-[%"YCoor"%] )<=3287',0)

  It can look confuse at first for newbies (like myself) the fact that
there are many "XCoor" and "YCoor" spread all along.  In this case both
layers have the same attributes, they are very similar.

The 'qgis:selectbyexpression' is a processing algorithm that have the
following description:


processing.runalg('qgis:selectbyexpression', layername,
expression,method)

  The layer name is the 'RcvPoints'.
  The method is : 0 (create a new selection)

  The expression is : abs("Xr"-"Xs")<=3900 and abs("Yr"-"Ys")<=3287

      Where appears "XCoor" above refers to layer 'RcvPoints'.
      Where appears [%"XCoor"%] refers to "XCoor" of current layer.


  One last info, I have tried this with the original SRC, tried using
EPSG:3857 (pseudo mercartor), and WGS84 (OTF on) without any problem.

  Worked like a charm.

  Hope this can be of use to someone.


  By the way, about that problem with the decimal point reported
before, I have tried to use it in the action expression and the same
error popped out, that is why there is no decimal point above.

  Sds.



> On Thu, 12 Nov 2015 14:11:19 -0200, "Fernando M. Roxo da Motta"
> <petro at roxo.org> wrote:
> 
>   Once again I am answering myself.
> 
>   I played a little bit with the "select using an expression" on the
> Recs layer.  I used (just an example) :
> 
> abs(  "XCoor"  - 813040. ) <= 3900. and
> abs(  "YCoor"  - 8886265. ) <= 3287.
>     
> And I got an error :
> 
>     Parser Error:
>     syntax error, unexpected Unknown_CHARACTER, expecting COMMA or ')'
> 
>     Eval Error:
>     No root node! Parsing failed?
> 
> After a lot of editing and all kind of guesswork I found that the
> problem were with the decimal points!   In order to make the
> expression work I had to rewrite as:
> 
> abs(  "XCoor"  - 813040 ) <= 3900 and
> abs(  "YCoor"  - 8886265 ) <= 3287
> 
>   Both "XCoor" and "YCoor" are floating point coordinates.  I thought
> that it could be something related to the l11n and that I should use
> a decimal comma in place of decimal point.  No, the error kept popping
> out.   Finally to isolate the l11n I started Qgis as:
> 
> $  LC_ALL=C  qgis
> 
>   The error remained the same, the only way to use the expression was
> removing the decimal points.
> 
>   Is it a "undocumented feature" (aka bug) or can it be something in
> my configuration/installation?
> 
>   I am using Qgis 2.12.0-Lyon on Xubuntu 12.04 64 bits.
> 
> 
>   Sds.
> 
> > 
> > 
> >   Hi all,
> > 
> > 
> >   I am attaching a small jpeg image in the hope that the list allow
> > it.  All descriptions bellow are based on this image.
> > 
> >   As (hopefully) can be seen I have two point layers, the green ones
> > called Recs and the red ones called Src. 
> > 
> >   To each Src point there is a subset of the Recs related based on a
> > rectangle, that  is all Recs inside a rectangle centred at the Src
> > will be activated when that particular Src is activated.  This is
> > the only relation and, of course, the rectangle of a Src point will
> > share some Recs from other nearby Src, but it is not a problem as
> > each Src is activated separately.
> > 
> >   Hope this is not too confuse.
> > 
> >   Now my question, is there a way to define an action so that when I
> > click a Src point all related Recs be highlighted?   Can be a
> > selection or whatever other suitable method.
> > 
> >   Thanks in advance.
> > 
> > 
> >   Roxo
> > 
> 
> 
> 
> 
> 
> 
> 
> 
>   Roxo
> 








  Roxo

-- 
---------------- Non luctari, ludare -------------------+ WYSIWYG
Fernando M. Roxo da Motta <petro at roxo.org>              | Editor?
Except where explicitly stated I speak on my own behalf.|  VI !!
      ( Usuário Linux registrado #39505 )               | I see text,
------------ Quis custodiet ipsos custodes?-------------+ I get text!
 



More information about the Qgis-user mailing list