2

I have a point layer and I wish to extract a random sample of these points across the dataset based on a given attribute.

For example I would like to select randomly 25 points with attribute "A", 50 points with attribute "B", 40 points that are attribute "C".

The selected samples must also be well distributed spatially and not all clustered together. How to achieve it in QGIS?

2

2 Answers 2

2

To select randomly points you find the function "random selection" and "random selection within subsets" in the toolbox under Vector/Research tools (or just search after random selection) --> no new layer is generated by this algorith.

Another function is "random extract", in this case you can extract a number of feature out of the selected features --> new layer is generated by this algorith.

1

Solution attempt for QGIS

Is the QGIS "Random selection within subset" selecting spatially random or randomly from the attribute table? shows, that the selection is not made spatially, but randomly from the attribute table, so features will not be equally spatially distributed. There might be solutions using plugins or some neat Python code, but I cannot provide that. If a random selection by attribute does suffice, continue the following steps.

There are different methods to get your sample data: random extraction or random selection by attributes or expressions. You can find them in the toobox under 'vector selection'.

enter image description here

You have to decide wether you want to extract your sample to a new layer and continue your work there or want to keep all data together and just work with a selection within your layer.

To achieve your differentiation by attribute, I'd suggest to first select all features with attribute "A" using 'select features by value' (shortcut key F3 should be assigned by default).
Next you use 'random extract' from the toolbox. Choose your layer and make sure you check the "use only selected features" checkbox:
enter image description here

Then choose Method 'Number Of Features' and type in your desired number.
Then run your process.

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.