I am trying to figure out exactly what is being randomly selected. I have a layer of road segments and I would like it to select a road segment at random within a neighborhood (the subset). This would be equivalent to selecting a random row in the attribute table within each neighborhood.

This seems to work but I feel (I know it is hard to actually judge if something is random) like it is selecting more segments in less dense areas. This got me wondering if it is actually doing something closer to generating random points within each neighborhood and selecting the nearest segment to each.

So is it randomly selecting a row in the attribute table, randomly selecting points in space, or something else?

  • You should be able to get the code for the tool as most QGIS plugins are open source, you can read that to see exactly what it's doing. Jun 2 '15 at 21:34
  • 1
    Try here: github.com/qgis/QGIS/blob/…
    – Stev_k
    Jun 2 '15 at 22:41
  • If someone who can read the code can confirm that else: selFeat = random.sample(FIDs, selVal) means that selection is based on feature IDs, please make a feature request to QGIS tracker for improving the documantation.
    – user30184
    Jun 3 '15 at 5:07
  • I appreciate the generous assumption that I can read the code (which maybe I sort of can). random.sample is doing this docs.python.org/2/library/random.html. So I think if this bit "while fit.nextFeature(inFeat): atMap = inFeat.attributes() if atMap[index] == i: FID = inFeat.id() FIDs.append(FID) "is just filling FIDs with the attribute ids for each subset then it is indeed doing what I wanted and selecting randomly from the attribute table. I'll make the feature request. Thanks Jun 4 '15 at 13:04

The fact that the code snipped linked above uses FID = inFeat.id() shows that the tool is working on a random selection of the IDs, therefore this will not be "spatially random". The term is a little unclear to me so I'm not sure how they are different, but what is clear is that the tool appears to be operating on a random basis in terms of the ID table of the features, thus the true degree of randomness I imagine will depend on how they are ordered within the file (and also the algorithm used by the python random module.

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.