3

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)

enter image description here

  • You most likely chose use attribute of first feature (one to one) when joining attributes by position. If you choose one 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. – Erik Mar 27 at 9:30
  • The problem is, that i have a net. For one line a point A is the start, while for another line this point A is the end. Thats why I can't divide my vertices into start-/endpoints – Julz_Mos Mar 27 at 9:35
  • Could u join any screenshot ? – snaileater Mar 27 at 9:36
5

In QGIS I can suggest using a Virtual Layer through Layer > Add Layer > Add/Edit Virtual Layer...

Let's assume we have two layers "points_layer" (red) and "lines_layer" (grey) respectively, see image below.

input

With the following query, it is possible to achieve the result, i.e. to add only the names of my vertices (from line intersection, duplicates deleted) to the attributtable 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 follwoing

result


References:

| improve this answer | |
  • Thanks a lot! Works perfect! – Julz_Mos Mar 27 at 11:01
  • Is there a way to do the same via Python-script? – Julz_Mos Apr 30 at 7:11
  • yes, for sure with PyQGIS. Have you tried something already? – Taras Apr 30 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 May 5 at 15:07
  • I would suggest putting it as a completely new question on GIS SE. – Taras May 5 at 15:09

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.