I have a polygon grid with 1 square kilometer area cells, and over it a set of points, like so:

points over grid

What i need to do is select and extract only a single random point per grid cell.

I could do that manually and it wouldn't take too much time as the area i have to cover is not that big, but is there is another way to do this?


2 Answers 2


You can easily achieve this using function from processing toolbox:

  1. Take grid cell and join its id (or other unique) attribute to related points - Use Join attributes by location and join unique attribute (i.e. "id_grid") from grid layer to point layer. This create new point layer with new attribute - "id_grid" of corresponding grid.

  2. Select only one point per gird - Use Random selection within subsets. As input choose your new layer from step one, for ID Field select "id_grid" and set number required points to be selected (in your case 1)

  3. Extracting to new point layer - Right click on layer, select Save As..., set output parametres (format, CRS...) and check Save only selected features


Another solution is to create an R Script GUI widget, which will run just like any other tool in the processing toolbox. The script below will allow you to select from you layers a polygon and a point data set, and will return a randomly sampled set of points wherein no more than one point will remain in within each individual polygon:

##output=output vector

samp <- lapply(1:nrow(polygons),function(i){
  x <- points[polygons[i,],]
  if (nrow(x) == 0){
  } else {
    sub <- sample(1:nrow(x), size = 1)

output = Reduce(rbind,samp[unlist(lapply(samp,function(i) class(i) != "NULL"))])

Note that if this is your first time running an R Script in QGIS, the first time you run it may take several minutes because it has to install the libraries. Each time after that will be significantly faster.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.