3

I am doing a work which I need to sample random points for many layers (classification of land use). Then, I'm trying to do a loop with my several layers and applied a functions of random pointos. I would like to use Random Points... functions (tool that I find in Menu>>Vector>>Research Tools>> Random Poits) because there I would choose 20 points pet class. This tool allows to make this.

It function (Random points...) belongs to fTools plugin, however I didn't find it functions in python console. All information that I saw in internet wasn't help me (or I couldn't understand).

How can I put this tool (Random points...) in my script? Is it possible?

enter image description here

Diogo Caribé
  • 1,960
  • 1
  • 23
  • 37

1 Answers1

3

You could use tools from Processing framework in PyQGIS. I think the tool you need from fTools is already in Processing, and it's called "Random points in layer bounds."

Just follow the same logic explained in Cannot run standalone QGIS script for running a Processing algorithm in PyQGIS. You'll need to call the tool like this:

general.runalg('qgis:randompointsinlayerbounds', vector, point_number, min_distance, output)

and pass the proper parameters:

  • vector: a polygon layer.
  • point_number: default 1.
  • minimum_distance: default 0.0
  • output: path to the output layer (e.g., '/tmp/output.shp').

Hope it helps.

Germán Carrillo
  • 36,307
  • 5
  • 123
  • 178
  • This function that you advised to me doen't work how I want. My sample design is stratified, and I would like randomized 20 points per class. The problem is that only possibility in "Random points in layer bounds" is randomized number of sample points for all extension of layer. – Diogo Caribé May 22 '15 at 01:18