Hey everyone.
I have a raster dataset (bshl_112p_srf) that I want to split up according to the classes that I have defined.
These classes are defined as:
158-535
535,0000001-686
686,0000001-1473
I have tried to use raster calculator to do this but it doesn't work. To extract the first class I tried to type:
Con("bshl_112p_srf" <= 535,"bshl_112p_srf")
, however I get an error for this expression.
What do I do wrong? Also, how would you extract the middle class (where you both need to have a <= and >= ).
Would it be something like:
Con("bshl_112p_srf" >= 535,0000001 & <=686,"bshl_112p_srf")
Thank you!
best regards
Ditlev Reventlow
Solved! Go to Solution.
An additional parenthesis when using &.
like
Class 1 = Con(("bshl_112p_srf" >= 158) & ("bshl_112p_srf" <= 535), "bshl_112p_srf")
Class 2 = Con(("bshl_112p_srf" > 535) & ("bshl_112p_srf" <= 686), "bshl_112p_srf")
Class 3 = Con(("bshl_112p_srf" > 686) & ("bshl_112p_srf" <= 1473), "bshl_112p_srf")
Hope this will work
Class 1 = Con("bshl_112p_srf" >= 158 & "bshl_112p_srf" <= 535, "bshl_112p_srf")
Class 2 = Con("bshl_112p_srf" > 535 & "bshl_112p_srf" <= 686, "bshl_112p_srf")
Class 3 = Con("bshl_112p_srf" > 686 & "bshl_112p_srf" <= 1473, "bshl_112p_srf")
Great thanks!
I tried to copy your statements but I get error 000539 error running expression rcexec().
What could the reason for this be?
You need to copy the Con() statement only. Try selecting the layers from Layers and Variables in Raster Calculator dialog box. One expression for each output raster.
I typed in raster calculator with those variable and expressions:
Con("bshl_112p_srf" >= 158,0000001 & "bshl_112p_srf" <= 535,"bshl_112p_srf")
It works now, but the output raster is first of all still covering the whole input original raster (not only the interval mentioned) and also the values are just termed 1. So all values have been reclassify to class 1, even though they were not inside the interval.
I would like to keep the original values (e.g. 535 instead of the new class 1) and only extract the values that are inside the interval. How can this be done?
Ditlev,
use this expression
Con("bshl_112p_srf" >= 158 & "bshl_112p_srf" <= 535, "bshl_112p_srf", 0)
Also in Environment Settings > Raster Storage. Define the value of No Data as 0 (zero)
I still get the same error message
I type this:
Con("bshl_112p_srf" >= 158 & "bshl_112p_srf" <= 535,"bshl_112p_srf",0)
And I have changed the nodata to 0.
Move the location of the input/output rasters to shorter path (e.g. D:\Raster_Data).
Try enclosing the whole expression inside Float().
like
Float (Con("bshl_112p_srf" >= 158 & "bshl_112p_srf" <= 535,"bshl_112p_srf",0)).
Don't copy-paste from here. Select the Raster layers and Operations from the Raster Calculator dialog-box.
Everything is typed in directly in raster calculator.
I tried to move it to a shorter path and added float(),
Float(Con("bshl_112p_srf" >= 158 & "bshl_112p_srf" <= 535,"bshl_112p_srf",0))
still the same error message.
If i type for instance:
Con("bshl_112p_srf" ==510 ,"bshl_112p_srf")
then this works with no problem. So the problem should be related to the <= and >=.