0

I got a point-layer Points where all points lying exactly on the vertexes of the polygons of a polygon-layer Polygons.

How do I join all numbers of the point-layer to the polygon-layer?

All algorithms I used didn't really work (NNjoin, MMQGIS, select attributes by location etc.).

What I need is to bring the column Nr into multiple columns of the polygon-layer like Nr_1, Nr_2, Nr_3, Nr_4. To bring it into one column like including a separator would also work.

I'm running QGIS 3.16.3.

enter image description here

PolyGeo
  • 65,136
  • 29
  • 109
  • 338

1 Answers1

2

You can achieve what you want e.g. by running custom PyQGIS script in QGIS's Python console. First, open attribute table of the polygon layer and create a new column to it (named here as ListOfNrs). Second, go to Python console (Ctrl+Alt+P), open script editor, paste the following code in it and press the green triangle to execute the script.

mapcanvas = iface.mapCanvas()
layers = mapcanvas.layers()

Assuming that first layer contains point data

and second layer contains polygon data

for a in layers[1].getFeatures(): temp = list() prov = layers[1].dataProvider() targetfield = layers[1].fields().lookupField('ListOfNrs') for b in layers[0].getFeatures(): if a.geometry().intersects(b.geometry()): temp.append(b["Nr"]) temp2 = ",".join(temp) atts = {targetfield: temp2} # call changeAttributeValues(), pass feature id and attribute dictionary prov.changeAttributeValues({a.id(): atts})

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Pauliina
  • 91
  • 3
  • it works well if both columns 'Nr' in Layer "Points" and 'ListOfNrs' in Layer "Polygons" are strings. Is there a possibility to extend the code by a buffer if the any point is not exactly on the vertex of a polygon? THX for great help by now – thompson82 Aug 26 '21 at 05:40