Example with vector output
This scripts takes input vector data and randomly samples Size points over it. The result is returned as a vector layer.
Script
##Point pattern analysis=group
##Sample random points=name
##Layer=vector
##Size=number 10
##Output= output vector
Layer_sp = as_Spatial(Layer)
pts = spsample(Layer_sp,Size,type="random")
Output = SpatialPointsDataFrame(pts, as.data.frame(pts))
Script lines description
- Point pattern analysis is the group of the algorithm.
- Sample random points is the name of the algorithm.
- Layer is the input vector layer.
- Size is the numerical parameter with a default value of 10.
- Output is the vector layer that will be created by the algorithm.
- Convert from sf format to older sp format, for which
spsample()
works - Call the spsample function of the sp library and pass it to all the input defined above.
- Create the output vector with the SpatialPointsDataFrame function.
That’s it! Just run the algorithm with a vector layer you have in the QGIS Legend, choose a number of the random point, and you will get them in the QGIS Map Canvas.