2

The random point tool in QGIS 2.4 works perfectly fine through the GUI, but I can't figure out how to automate this tool via Python and/or the modeller.

Specifically, under the menu items: Vector | Research Tools | Random points, I am able to create a random point file that is based on a column in the input Shapefile. When I examine Processing | History and log, I am unable to find the python equivalent command to automate this command.

There's a similar algorithm under the Processing Toolbox called "Random points inside polygons (variable)", but this plugin appears to be slightly different than its GUI counterpart (e.g., it contains an option to input a minimum distance between points). More importantly, this version of the tool does NOT work with the very same shapefiles that work when using the GUI version of the random point tool mentioned above.

How I can call the GUI version of the "Random Points" tool via the modeller and/or Python?

0

While I'm not answering the original question, as it is related to the GUI version of Random Points, I can include the answer that I ultimately used in the hopes it might be useful to someone else.

This answer is based on a patched version of the "Random points inside polygons (variable)" algorithm found in the Processing Toolbox (QGIS 2.4). A case-specific answer can be found on a related Stack Overflow question, but I've reproduced it here in generalizable form:

    import glob
    import os
    import processing

    os.chdir("/home/mydir/vector") # directory containing shp files to be processed

    columnid = ['SAMPLES'] # column ID containing number of samples per polygon

    for x in glob.glob("prefix*.shp"):
        for y in columnid:
           # iterates through each shp file, using the same columnID, and outputs random points that are 1000 units (meters) apart
           exec('processing.runalg("qgis:randompointsinsidepolygonsvariable","/home/mydir/vector/{w}",0,"{y}",1000,"/home/mydir/vectorsamples/{x}_{y}.shp")'.format(w=x, x=x.rstrip('.shp'), y=y))

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.