4

I am looking for a way in QGIS to randomly select features within my shapefile. The selected features together need to sum up to more or less 2000m2. So, it is not selecting 10% of the features, but 10% of the sum of one attribute of the features (20 000 m2 in this case)

4

I don't think ther's an out of the box solution for this. One option for you would be to use Python to create a script. If however, you aren't familiar with coding you can try the following...

Create your area field using field calculator and if you haven't got one already create an id field with sequential numbers from 1 to the total number of features in the layer. Then export the layer to csv and open in excel.

Order the table by the id column and create a new field calling 'running_total'. Assuming your area field is column c and row 1 are your headers, calculate the running total with the formula =SUM($C$2:$C2). If you're familiar with excel you'll notice that all the references are absolute except the last one, so Drag this formula to the bottom and you'll get the running total. This is better explained here. Note down the id where the running total is closest to 20000.

Back in QGIS select by attribute all features who's ids are less than or equal to the id you noted earlier.

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.