This Python script works. But it can be used only in QGIS Python Editor. It is not a Processing script. ```python from PyQt5.QtCore import QVariant # layers P = QgsProject.instance().mapLayersByName("Posibility_Layer")[0] S = QgsProject.instance().mapLayersByName("Stop_Layer")[0] S.startEditing() # add new fields if S.fields().indexFromName('near_pl_id') == -1: # field for polygonid of the nearest point S.addAttribute(QgsField('near_pl_id', QVariant.Int)) if S.fields().indexFromName('near_ps_id') == -1: # field for possibilityid of the nearest point S.addAttribute(QgsField('near_ps_id', QVariant.Int)) for s in S.getFeatures(): # get points which have different polygon-id than the stop-point itself has request = 'polygonid != ' + str(s["polygonid"]) distances = {p: s.geometry().distance(p.geometry()) for p in P.getFeatures(request)} # get the feature which has the minimum distance value nearest_point = min(distances, key=distances.get) # you may need to change 'possibilit' as 'possibilityid', (character limit of shapefile) s['near_ps_id'] = nearest_point["possibilit"] s['near_pl_id'] = nearest_point["polygonid"] S.updateFeature(s) S.commitChanges() ``` Result: [![enter image description here][1]][1] [![enter image description here][2]][2] [1]: https://i.sstatic.net/am4Og.png [2]: https://i.sstatic.net/Opw8t.png