I'm using QGIS 3.8 with GRASS 7.6.1
I want to add only the names of my vertices (from line intersection, duplicates deleted) to the attributtable of my lines (like start and end node). Every line has only two vertices.
What I tried:
geom_to_wkt(start_point($geometry))
--> gives me the coordinates (I need the name) of my real nodes not of the vertices"add by position" only transfers the name of one vertices (but I need both)
1 Answer 1
In QGIS there is a possibility using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer...
Let's assume there are two layers 'points_layer' (red) and 'lines_layer' (grey) respectively, see image below.
With the following query, it is possible to add only the names of my vertices (from line intersection, duplicates deleted) to the attributes table of my lines (like start and end node).
SELECT
l.*,
p1.Info AS start_point_info,
p2.Info AS end_point_info
FROM
"lines_layer" AS l
LEFT JOIN
"points_layer" AS p1
ON st_equals(start_point(l.geometry),p1.geometry)
LEFT JOIN
"points_layer" AS p2
ON st_equals(end_point(l.geometry),p2.geometry)
The output Virtual Layer will look like as following
References:
-
Thanks a lot! Works perfect!Julz_Mos– Julz_Mos2020年03月27日 11:01:34 +00:00Commented Mar 27, 2020 at 11:01
-
Is there a way to do the same via Python-script?Julz_Mos– Julz_Mos2020年04月30日 07:11:28 +00:00Commented Apr 30, 2020 at 7:11
-
yes, for sure with PyQGIS. Have you tried something already?2020年04月30日 07:35:18 +00:00Commented Apr 30, 2020 at 7:35
-
I'm a beginner in python and tried a few things... If possible I want to add the information to a existing line-layer ("line_layer"). My (definetly wrong!) code:
for f in line_layer.getFeatures(): geom = f.geometry().asMultiPolyline() start_point = QgsPoint(geom[0]) end_point = QgsPoint(geom[-1]) f.['node1'] = QgsGeometry.nearestPoint(start_point) f.['node2'] = QgsGeometry.nearestPoint(end_point)
This is wrong in many ways... I want to get the name of the point (point_layer) (in your example feature "Info") but I don't know how to do that.Julz_Mos– Julz_Mos2020年05月05日 15:07:44 +00:00Commented May 5, 2020 at 15:07 -
I would suggest putting it as a completely new question on GIS SE.2020年05月05日 15:09:00 +00:00Commented May 5, 2020 at 15:09
Explore related questions
See similar questions with these tags.
use attribute of first feature (one to one)
when joining attributes by position. If you chooseone to many
you will get two lines which overlap. Workaround: Divide your vertices into start- and endpoints. First join the start-, then join the endpoints to your lines. The problem is, that the name-column is the same for both points, and only one attribute of the same column can be attached to another feature/layer.