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:
- Creating a new GPKG layer of geometry type = Lines (lineLayer) and adding one field: fromID.
- Copying all points, changing the wkt from "PointZ" to "LineStringZ", giving them some fake geometry and pasting them to the lineLayer.
- 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.