1

iIt is quite obvious to me that the rasterset A, B within the NDVI equation, --calc='"((A-B)/(A+B))"' with cell_value=0 will lead to the above error (division by zero). How can I avoid the error?

1

Try

 --calc='"numpy.divide(A,B,out=np.zeros_like(A), where=(B*A)!=0)"'

will output 0 where either A or B is zero.

1
0

You can not avoid the error but you can handle the error. If you post your code you might get a more specific answer. In any case have a look at Python error handling and more specifically how to handle zero division errors.
Something like this:

try:
    your code here
except ZeroDivisionError:
    pass

Check out these links. Error handling From Python From stack exchange.

2

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.