3

I have two separate point layers. The first point layer contains the locations of 100 sensors which are aligned in one specific direction (for example: Asten). The second point layer contains the location-coordinates of the possible directions.

The attribut table of a sensor node looks like following: enter image description here

The attribut table of a direction node looks like following: enter image description here

What I am trying to do is to compare each point of point-layer-1 with each point of point-layer-2. If the "location"-attribut of the point-layer-2 node is equal to the "direction"-attribut of the point-layer-1 node, those two points should be connected to a vector. The result should look like this: enter image description here

The result vectors should be stored in a new line-layer I suppose. Is there a way to do this?

  • 1
    Please remember that questions here are expected to provide not only what you want, but what you have attempted, and what has gone wrong. Coding questions (those tagged with python) are expected to contain code. The answers to most "Is there a way to do this?" Questions yield several different ways (this is especially true when Python is in the mix). For this reason, showing where you have started and where you were headed is important to finding a solution that will integrate into your process. – Vince Dec 27 '17 at 12:18
7

On the sensor layer, go to symbology and change the symbol to a "Geometry Generator". Choose "Line" as type.

Enter the following expression

make_line(
  -- the current feature's geometry (point from sensor layer).
  $geometry,
  -- the matching feature's geometry from the layer 'location_coordinates'
  -- where the attribute 'location' matches the current feature's attribute
  -- "direction"
  geometry(get_feature('locations_coordinates', 'location', "direction"))
)

PS: in this case there will be no new line-layer, but since you "only" suppose, I guess that should be good enough. The up-side is, you can add as many new locations and sensors as you wish or change other data and the lines will just adjust to the data as it is updated.

  • I tried the your suggested solution, but the expression is invalid. The error I am getting when I copypaste your expression: syntax error, unexpected '(', expecting $end. How can I solve this? Thank you for helping! – applebrown Dec 27 '17 at 11:41
  • It says that get_feature takes 3 arguments. Is it possible that the parameter 'location' and "direction" belong to the get_feature function and not to the make_line arguments? – applebrown Dec 27 '17 at 11:59
  • You are of course right :) – Matthias Kuhn Dec 27 '17 at 12:02
  • amazing! It works, thank you so much for your help :) – applebrown Dec 27 '17 at 12:07
  • Is there a way to store the vectors into a separate line-layer too? Because I need this vectors for calculating the azimuth. – applebrown Dec 27 '17 at 12:08

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.