Hey, so, having frustraited over this for ages I give up and will ask
I have a conditional statement I applied to an NDVI layer to apply a double sided membership function to it
It is in 32 bit float as it is decimal. The following statement was used
Con((Float("spainndvi" < 0.13)) & (Float("spainndvi" > 0.9)), 0, Con((Float("spainndvi" >= 0.13)) & (Float("spainndvi" <= 0.32)), (Float("spainndvi" - 0.13)) / (0.32 - 0.13)), Con((Float("spainndvi" >= 0.6)) & (Float("spainndvi" <= 0.9)), (Float(0.9 - "spainndvi")) / (0.9 - 0.6), 1))
The odd thing is it worked when I last used it but having miss named the file I deleted it by accident, went to re-run the statement and it just gives me an error. Is there something obviously wrong with my statement? Thanks
Messages
Executing: RasterCalculator Con((Float("spainndvi" < 0.13)) & (Float("spainndvi" > 0.9)), 0, Con((Float("spainndvi" >= 0.13)) & (Float("spainndvi" <= 0.32)), (Float("spainndvi" - 0.13)) / (0.32 - 0.13)), Con((Float("spainndvi" >= 0.6)) & (Float("spainndvi" <= 0.9)), (Float(0.9 - "spainndvi")) / (0.9 - 0.6), 1)) "E:\Users\GTAV\My Documents\ArcGIS\Default.gdb\rastercalc"
Start Time: Tue Jul 04 17:25:11 2017
Con((Float(Raster(r"spainndvi") < 0.13)) & (Float(Raster(r"spainndvi") > 0.9)), 0, Con((Float(Raster(r"spainndvi") >= 0.13)) & (Float(Raster(r"spainndvi") <= 0.32)), (Float(Raster(r"spainndvi") - 0.13)) / (0.32 - 0.13)), Con((Float(Raster(r"spainndvi") >= 0.6)) & (Float(Raster(r"spainndvi") <= 0.9)), (Float(0.9 - Raster(r"spainndvi"))) / (0.9 - 0.6), 1))
ERROR 000539: Error running expression: rcexec()
Traceback (most recent call last):
File "<expression>", line 1, in <module>
File "<string>", line 5, in rcexec
File "e:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\sa\Functions.py", line 263, in Con
where_clause)
File "e:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\sa\Utils.py", line 53, in swapper
result = wrapper(*args, **kwargs)
File "e:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\sa\Functions.py", line 257, in Wrapper
where_clause)
File "e:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\geoprocessing\_base.py", line 510, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
ExecuteError: ERROR 999999: Error executing function.
An invalid SQL statement was used.
An invalid SQL statement was used. [VAT_boole_ras]
An invalid SQL statement was used. [SELECT * FROM VAT_boole_ras WHERE E:\Users\GTAV\My Documents\ArcGIS\Default.gdb\ifthe_ras1]
Failed to execute (Con).
The table was not found. [VAT_ifthe_ras1]
Failed to execute (RasterCalculator).
Failed at Tue Jul 04 17:25:24 2017 (Elapsed Time: 12.36 seconds)
just working on syntax... it looks like you were whipping in brackets until problems went away
Con((Float("spainndvi" < 0.13)) & (Float("spainndvi" > 0.9)), 0,
Con((Float("spainndvi" >= 0.13)) & (Float("spainndvi" <= 0.32)),
(Float("spainndvi" - 0.13)) / (0.32 - 0.13),
Con((Float("spainndvi" >= 0.6)) & (Float("spainndvi" <= 0.9)),
(Float(0.9 - "spainndvi")) / (0.9 - 0.6), 1)))a = Float("spainndvi"
# would be better
# generically
Con((a < 0.13) & (a > 0.9), 0,
Con((a >= 0.13) & (a <= 0.32), (a - 0.13) / (0.32 - 0.13),
Con((a >= 0.6) & (a <= 0.9), (0.9 - "spainndvi") / (0.9 - 0.6), 1)))
# I think.....
John... you posted this as a 'discussion' not a 'question'. If you need an answer, the 'questions' are better since they garner more attention than discussions. Generally 'discussions' are only addressed when people have time or they are interested.
Hmm I had that before but it was having issues because it was decimal which is the reason I added float, but that appears to have fixed it so thanks a lot Dan, very helpful as always
John.... a bracket was out of order... can't remember which one off hand... the float thing is just to make your life easier that trying to do things all at once. You can have multiple lines in the raster calculator, so there is no need to go through the pain of trying to get it all in one line with all things that need to be done.
Apart from the parenthesis, the operators also look incorrectly placed. e.g. a number cannot be less than 0.13 and greater than 0.9. Or maybe you wanted the value to be 0.09 instead of 0.9.
Check the following expression:
Con((Float("spainndvi") < 0.13) | (Float("spainndvi") > 0.9), 0, Con((Float("spainndvi") >= 0.13) & (Float("spainndvi") <= 0.32), (Float("spainndvi") - 0.13) / (0.19), Con((Float("spainndvi") >= 0.6) & (Float("spainndvi") <= 0.9), (0.9 - (Float("spainndvi"))) / (0.3), 1)))
EDITED: The above expression to include OR "|"
interesting... but it doesn't produce an error, just an unexpected response.
(a < 0.13) & (a > 0.9)
Out[2]: False
Error might be due to incorrect use of parenthesis.
it was... can't remember which one was misplaced and if I can remember, that made one missing. The prior step to simplify things would have removed a whole load of parenthesis... I think the help files should show some multiline examples instead of the simple ones they do... perhaps when we have time
I think It should be (Float("spainndvi") <= 0.32) instead of (Float("spainndvi" <= 0.32))