3

I have a layer that includes points for electric poles (Circles) and transformers (triangles). Transformers can be on poles or on their own. I would like to displace the transformers only if they are on top of a pole, keeping their exact location when they are on their own so they follow the electric wires. I have tried a conditional in the displacement expression box:

if( intersects(  $geometry ,  get_feature(  @layer_name , "Type" , 'Pole' )),1,0)

but it is not working.

What I don't want

What I don't want

What I want ONLY when there is a Pole (circle) present

What I want ONLY when there is a Pole (circle) present.

  • if your layer is a point layer i don't think the intersect operator will be of any use at that stage ... maybe try to add a "buffer" operator before testing the intersection. – snaileater Jun 24 '17 at 7:44
  • Can I run the buffer as a symbology script? – Sergio C. Jun 24 '17 at 7:49
  • i"m not sure of my comment ... lol ... are your points strictly overlapping ? can u have more than 2 points overlapping ? – snaileater Jun 24 '17 at 8:01
  • 1
    Did u check the "point displacement" rendering style offered by QGIS in the layer properties ? I think it almost does what u're expecting ... – snaileater Jun 24 '17 at 8:17
  • The points overlap perfectly as I created them with snapping in ArcMap. The point displacement option works very well, but I want to set a rule to do not displace the triangles when there is not a circle present. Thank you! – Sergio C. Jun 24 '17 at 8:59
6

My guess is you are probably trying to something like this:

CASE 
WHEN count_distinct( "id" , group_by:= geom_to_wkt( $geometry ) ) >= 2
THEN '0.0,5.0'
ELSE '0.0,0.0'
END  

to be put into the data defined override expression in the Offset XY. (I used an "id" field but you can use any field in your attribute table.)

In the above example '0.0,5.0' is the XY offset, which moves the symbol 5.0 mm to the south. It does not have to be 5.0 and any number will do. If count_distinct() returns 1, it means there is no overlapping point and the point symbol does not move ('0.0,0.0').

Please note this expression does not discern if the overlapping points are Poles or Transformers. I just could not imagine two Poles sitting at the same location, and assumed that any overlap would mean Pole & Transformer.

enter image description here

  • 1
    wow ... nice one ! when i look to the qgis functions documentation it is really not obvious to me these aggregate functions can work at a geographical level ... where did u find the information ? – snaileater Jun 24 '17 at 13:50
  • @snaileater Good point about aggregate. Honestly I had not think about possibility of using geometry information directly in the function. Quick test on CASE WHEN count_distinct( "id" , group_by:= $geometry ) >= 2 worked, without having it wrapped in geom_to_wkt(). Great, thanks so much! – Kazuhito Jun 24 '17 at 15:04
  • 2
    Or, if the overlapping points are many, you could use the theme 'Point displacement' pigrecoinfinito.wordpress.com/2017/05/01/… – pigreco Jun 24 '17 at 15:12
  • 1
    Thanks @pigreco for information. Care to post that approach as answer? I am interested in it, too. – Kazuhito Jun 24 '17 at 15:19
  • 1
    @pigreco Thanks! Will follow the instruction and the YouTube video. I agree that learning step-by-step by video is intuitive and thus powerful tool for complex procedures. You do provide great videos. – Kazuhito Jun 24 '17 at 16:26

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.