Bug report #11215

"Random points inside polygons (variable)" progress error halts algorithm

Added by d d about 6 years ago. Updated over 5 years ago.

Assignee:Alexander Bruy
Affected QGIS version:2.4.0 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:fixed/implemented
Crashes QGIS or corrupts data:No Copied to github as #:19525


Shapefile with ~3000 rows contains field column containing the number of samples per polygon: "SAMP300" (integer). Algorithm fails to run.

Algorithm log:

Algorithm Random points inside polygons (variable) starting...
float division by zero See log for more details

History and log:

Uncaught error while executing algorithm
Traceback (most recent call last):
Traceback (most recent call last):
File "/usr/share/qgis/python/plugins/processing/core/GeoAlgorithm.py", line 217, in execute
File "/usr/share/qgis/python/plugins/processing/algs/qgis/RandomPointsPolygonsVariable.py", line 101, in processAlgorithm
total = 100.0 / pointCount
ZeroDivisionError: float division by zero

I'm not sure why pointCount would ever equal 0, as I definitely have more than 0 values in total; however, some features do contain 0 values.

Changing line 101 in RandomPointsPolygonsVariable.py to the following allows the algorithm to complete:

total = 100.0 / (pointCount + 1)

I'm not sure if my modification affects the number of samples produced, but on first glance, everything looks OK. It appears that the affected line relates to the progress indicator only, so it appears safe to use this modification, but do so at own risk. Hopefully the plugin author will be able to pinpoint the actual issue.

vector.7z - example of shp file that produces the reported error (1.5 MB) d d, 2014-09-19 06:17 AM

Associated revisions

Revision cc307578
Added by Alexander Bruy about 6 years ago

[processing] avoid division by zero in random points alg (fix #11215)


#1 Updated by d d about 6 years ago

Perhaps a "better" solution is:

total = (pointCount / 100.0) * 100

This appears to avoid the issue with dividing by 0 without having to add a constant. The algorithm runs with the above modification, but as before, use at own risk.

#2 Updated by Alexander Bruy about 6 years ago

  • OS version deleted (Mint 17 (Ubuntu 14.04))
  • Operating System deleted (Linux)
  • Category changed from Python plugins to 94

Please provide sample dataset, I can't reproduce this with my test data.

#3 Updated by d d about 6 years ago

Alexander Bruy wrote:

Please provide sample dataset, I can't reproduce this with my test data.

I've attached an example file ("vector.7z") that produces the error I reported.

For the Number Field, use the "SAMP300" column (or "SAMP100", "SAMP30", "SAMP10" columns). Each of these columns is integer-based. I also use a minimum distance of 1000. You should get the same error as I reported. Modifying your script as I suggested appears to fix the problem, but it might have unintended consequences.

#4 Updated by Alexander Bruy about 6 years ago

  • Status changed from Open to Closed

#5 Updated by Alexander Bruy about 6 years ago

  • Resolution set to fixed/implemented

#6 Updated by Giovanni Manghi over 5 years ago

  • Category changed from 94 to Processing/Core

Also available in: Atom PDF