1

I was conducting Mean Coodinates process functions with weighted fields when I began faces ZeroDivision errors in some processes.

The Shapefile Data has been joined together with imported Spreadsheet data.

I have to run this simulation multiple times and about 70% of the times it has worked without errors while it is giving the following error with the combination of particular shapefiles with certain weighted means.

the error is:

Uncaught error while executing algorithm

Traceback (most recent call last):

Traceback (most recent call last):

File "C:/PROGRA~1/QGISCH~1/apps/qgis/./python/plugins\processing\core\GeoAlgorithm.py", line 217, in execute self.processAlgorithm(progress)

File "C:/PROGRA~1/QGISCH~1/apps/qgis/./python/plugins\processing\algs\qgis\ftools\MeanCoords.py", line 119, in processAlgorithm

cx = values[0] / values[2]

ZeroDivisionError: float division by zero

What is the issue and how can it be solved?

4
  • 2
    The issues seems to be that you can't divide by 0 eg. 3.4/0. This link reference "exception ZeroDivisionError" indicates "Raised when the second argument of a division or modulo operation is zero". Somewhere in your values for "values[2]" you have zeros present.
    – TsvGis
    Commented Jul 25, 2015 at 23:44
  • Try to add a print (values[2]) ; assert values[2] != 0 at line 118. As some point, this assertion will probably fail.
    – boardrider
    Commented Jul 26, 2015 at 12:20
  • Maybe there is no data in tour variable, check with a print or something else
    – jlSta
    Commented Feb 24, 2017 at 8:10
  • Welcome to gis.stackexchange! Please edit the title of your question to include enough information for future visitors to be able to find this thread when looking for the same problem.
    – underdark
    Commented Apr 19, 2018 at 20:30

1 Answer 1

1
if values[2] != 0:
    cx = values[0] / values[2]
else:
    cx = 0

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.