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.


##Point pattern analysis=group
##Sample random points=name
##Size=number 10
##Output= output vector
pts = spsample(Layer,Size,type="random")
Output = SpatialPointsDataFrame(pts, as.data.frame(pts))

Script lines description

  1. Point pattern analysis is the group of the algorithm.
  2. Sample random points is the name of the algorithm.
  3. The script does not use sf package; it instead uses packages sp and rgdal.
  4. Layer is the input vector layer.
  5. Size is the numerical parameter with a default value of 10.
  6. Output is the vector layer that will be created by the algorithm.
  7. Call the spsample function of the sp library and pass it to all the input defined above.
  8. 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.