5

I have a dataset of 5000 records which I've plotted over an OSM layer using QGIS and I wish to randomly select 50 from within a radius of 2km from a point of my choosing.

It is similar I think to this here where again the Select Features by Radius is almost what I'm aiming for, but unlike the previous question, I only wish to randomly select 50 points from within the 2km radius.

Using the Select Features by Radius, it looks like there would be approximately 300-400 points within any 2km radius. So a solution would have to be able to randomly select only a fraction of these.

6
  1. Select Feature by Radius like under the link you provided.

or

  1. Create a new shapefile with a single point, then create a buffer with needed radius for your point (Vector -> Geoprocessing -> Buffer) and eventually use it to select your points -> Research tools -> Select by location

  2. Vector -> Research tools -> Random selection will give you an opportunity to randomly select N of these.

enter image description here

3

I think Maxim Dubinin's answer is the best one if you need a fixed number of points - and it and will work on most versions of QGIS.

If you have a more recent version of QGIS (2.10+ ?), it's also possible to do random samples by simply selecting using an expression. In more recent versions a number of geometric functions have been made available.

I did this on a postgres layer, but it works on shapefile layers too.

For example, I used this expression to select around 20% of points which are within a 500m radius of the given point (show in red).

These are Pubs from OSM, and the CRS is OSGB (27700, which is in meters). The centroid() call is optional if your layer is of POINT geometry.

within(centroid($geometry),buffer(make_point(529517.422097, 180720.816783),500.0)) and randf(0.0,1.0)<=0.2

And a picture...

random selection of points within a radius

Note that you should probably have a spatial index on your layer or this might be a bit slow (under properties->layer, but this depends on data source).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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