I am developing a plugin using PyQGIS and PyQt5. I am calling qgis:randompointsinsidepolygons, where I am trying to give field input at VALUE parameter. It will take a variable number of points for each polygon in the layer. But somehow it is not using field for the same. Attaching the code snippet for the reference.

padding_op.dataProvider().addAttributes([QgsField("vlp1_num", QVariant.Double)])


for f in padding_op.getFeatures():
    aval_a = (float(f["final_a"])*perc)/100
    vlp1_size = a*b
    f["vlp1_num"] = int(aval_a/vlp1_size)


num = padding_op.fields().indexFromName('vlp1_num')

random_parameters = {'INPUT':padding_op,
random = processing.run('qgis:randompointsinsidepolygons', random_parameters)
random_op = random['OUTPUT']

Here, the number of points to be created in each polygon is stored in vlp1_num field. Algorithm is not considering, it seems.

  • 1
    See: gis.stackexchange.com/questions/325434/…
    – Bera
    Commented Oct 20, 2021 at 13:38
  • 1
    I think you are just passing it the field index (num variable) of the field vlp1_num as the VALUE argument, rather than any value in that field.
    – Matt
    Commented Oct 20, 2021 at 14:14

1 Answer 1


You pass the index number of the field when using num. Just use QgsProperty.fromExpression('"vlp1_num"') for parameter 'VALUE'.

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.