0

I'm trying use raster calculator that can export a raster to do different average values for for multiple layers. For example, I want to do averages for only the values and layers that are greater than 0. I'm trying to input Python code but it keeps failing. Here is a video where I try and explain my project if you need more context. https://www.youtube.com/watch?v=bt6ecPGjjDA&t=24s

I've also tried putting single quotes on the line but there is still a syntax error.

>>> import arcpy
... from arcpy.sa import *
... f1 = arcpy.Raster("S:/npenme2/Faunalyze\Feature_KB3_Right_Radius_14497/value")
... f2 = arcpy.Raster("S:/npenme2/Faunalyze\Feature_KB1_Right_Radius_14471_RC11/value")
... f3 = arcpy.Raster("S:/npenme2/Faunalyze\Feature_KB4_Right_Radius_14510/value")
... if value > 1:
... outraster = (f1 + f2 + f3)/3
... else:
... outraster = (f1 + f2 +f3)/3 - 1
... f123 = f1 + f2 + f3
... outraster = Con(f123 > 0, f123 / 3, f123 / 3 - 1)
... outraster.save(S:/npenme2/Faunalyze/rasterCalc)
... 
Parsing error SyntaxError: invalid syntax (line 12)
>>> 

I've also tried SQL on the actual raster calculator tool with this query. But it too does not work:

Con("Feature_KB3_Right_Radius_14497" + "Feature_KB4_Right_Radius_14510" + "Feature_KB1_Right_Radius_14471_RC11">0,(("Feature_KB3_Right_Radius_14497" + "Feature_KB4_Right_Radius_14510" + "Feature_KB1_Right_Radius_14471_RC11")/3), ("Feature_KB3_Right_Radius_14497" + "Feature_KB4_Right_Radius_14510" + "Feature_KB1_Right_Radius_14471_RC11")/3-1)) 
user2856
73.7k7 gold badges123 silver badges207 bronze badges
asked Mar 23, 2019 at 0:23
0

1 Answer 1

3

The error tells you exactly what is wrong and where IndentationError: expected an indented block (line 7). You need to indent lines in your if clause:

if value > 1:
 outraster = (f1 + f2 + f3)/3
else:
 outraster = (f1 + f2 +f3)/3 - 1

However, this code won't do what you want it to. You need to use Con:

f123 = f1 + f2 + f3
outraster = Con(f123 > 0, f123 / 3, f123 / 3 - 1)
outraster.save('S:/npenme2/Faunalyze/rasterCalc')
answered Mar 23, 2019 at 1:04
2
  • Thank you and sorry I accidentally copied my previous edit. I fixed the indentation error. I added the con statement but I'm still getting an error. I updated my question. Commented Mar 23, 2019 at 15:24
  • The if value > 1 won't work, that is what the Con replaces, remove it. Also, you didn't quote the filepath, see edit. Commented Mar 23, 2019 at 20:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.