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 ##load_vector_using_rgdal ##Layer=vector ##Size=number 10 ##Output= output vector pts = spsample(Layer,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.
- The script does not use sf package; it instead uses packages sp and rgdal.
- 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.
- 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.