I have a few random points that I generated within a polygon. I randomly selected one of the points and would like to buffer that point. In the case below, buffering will be applied to all points and not the selected point. Do I need to create a new memory layer of the selected point first? If so, how?
#Generating random points within an "aoi" polygon file
pnts = processing.runAndLoadResults("native:randompointsinpolygons", {'INPUT':aoi,
'POINTS_NUMBER':10,
'MIN_DISTANCE':0,
'MIN_DISTANCE_GLOBAL':0,
'MAX_TRIES_PER_POINT':10,
'SEED':None,
'INCLUDE_POLYGON_ATTRIBUTES':True,
'OUTPUT':'memory:'})
#Randomly Choose one of the Points
processing.run("qgis:randomselection",
{'INPUT':pnts['OUTPUT'],
'METHOD':0,'NUMBER':1})
#Buffering the point
pnt_buf = processing.runAndLoadResults("native:buffer",
{'INPUT':pnts,
'DISTANCE':3000,
'SEGMENTS':6,
'END_CAP_STYLE':0,
'JOIN_STYLE':1,
'MITER_LIMIT':3,
'DISSOLVE':True,
'SEPARATE_DISJOINT':False,
'OUTPUT':'memory:'})
You don't have to pass by an intermediary memory layer (though you could). You don't need to change much, just modify the input value of buffer processing tool like below.
Get a QgsVectorLayer instance (use your original code here):
Then setup your 'pnts' input to use just the selected features:
Buffering the point
EDIT:
actually i got a little bored and played with it some more, you could do somthing like:
But obviously it depends on how you want to apply/ integrate the code