1

I have a layer (pointLayer) with point features: Fields: ID, toID.

All points have a value in ID, some have a value in toID. If a point "A" has a value in toID, I want to display a line between point "A" and the point with the ID = point "A"'s toID. The line doesn't have to be stored permanently, but it would be good if it automatically appeared/disappeared upon a change of toID value.

How can I best achieve that?

My approach so far has been:

  1. Creating a new GPKG layer of geometry type = Lines (lineLayer) and adding one field: fromID.
  2. Copying all points, changing the wkt from "PointZ" to "LineStringZ", giving them some fake geometry and pasting them to the lineLayer.
  3. Then updating the geometry like:
geom_from_wkt('LineStringZ(' ||
x(geometry(get_feature('pointLayer','ID',fromID))) || ' ' ||
y(geometry(get_feature('pointLayer','ID',fromID))) || ' ' ||
z(geometry(get_feature('pointLayer','ID',fromID))) || ', ' ||
x(geometry(get_feature('pointLayer','ID',attribute(get_feature('pointLayer','ID',fromID),'toID')))) || ' ' ||
y(geometry(get_feature('pointLayer','ID',attribute(get_feature('pointLayer','ID',fromID),'toID')))) || ' ' ||
z(geometry(get_feature('pointLayer','ID',attribute(get_feature('pointLayer','ID',fromID),'toID')))) ||
')'
)

But that means if I change something in the pointLayer, I have to update the geometry of the lineLayer to see the changes.

Looks like I can achieve similar result using PointConnector, but that involves generating/updating the "from - to" table and the input layer each time (because the first field must be "the joining attribute found in the from-to list").

Another idea I got was to somehow use a virtual layer for this, i.e.:

SELECT "ID", "toID", geometry
FROM pointLayer
WHERE "toID" <> ''
....
and somehow update, or create the geometry.

But my SQL knowledge is minimal.

2

OK, so the keywords here were "Geometry generator" and "make_line". Thanks Val P, for leading me to those :). I solved this by simply specifying "Geometry generator" as the "Symbol layer type" and an expression:

make_line($geometry,geometry(get_feature(@layer,'ID', toID)))
| improve this answer | |

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.