2

From How can I reclassify an integer raster to a float raster?, I would like to reclassify an integer raster "cpraster3.tif" to a float raster. For example, I would like to reclassify "Value" = 1 into 0.27, "Value" = 2 into 1.00 ...

Here is my code:

test_reclass = Float(Con(("cpraster3.tif", "Value" = 1, 0.27, Con("cpraster3.tif", "Value" = 2, 1.00, Con("cpraster3.tif", "Value" = 3, 2.9, Con("cpraster3.tif", "Value" = 4, 2.94, Con("cpraster3.tif", "Value" = 5, 5.37, Con("cpraster3.tif", "Value" = 6, 10.35, Con("cpraster3.tif", "Value" = 7, 16.49, Con("cpraster3.tif","Value" = 7, 22.08, 0.0)))))))))

But I have this error message:

Failed to run script - syntax error - keyword can't be an expression

1 Answer 1

3

Use == which is the equality operator, not a single = which is the assignment operator (i.e a = 1 assigns the value 1 to the variable a). You can also shorten your expression by having the comparison as the first argument and dropping the Value field.

E.g:

test_reclass = Float(Con("cpraster3.tif" == 1, 0.27, Con("cpraster3.tif" == 2, 1.00, Con("cpraster3.tif == 3, 2.9, Con("cpraster3.tif" == 4, etc...

All those nested Con functions are quite unwieldy though. Have you considered using the Reclassify function instead?

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.