Extracting raster values according to different classes

5188
15
Jump to solution
07-01-2015 12:39 PM
DitlevReventlow
Occasional Contributor II

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

0 Kudos
1 Solution

Accepted Solutions
JayantaPoddar
MVP Esteemed Contributor

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



Think Location

View solution in original post

15 Replies
JayantaPoddar
MVP Esteemed Contributor

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")



Think Location
DitlevReventlow
Occasional Contributor II

Great thanks!

0 Kudos
DitlevReventlow
Occasional Contributor II

I tried to copy your statements but I get error 000539 error running expression rcexec().

What could the reason for this be?

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

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.



Think Location
DitlevReventlow
Occasional Contributor II

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?

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

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)



Think Location
DitlevReventlow
Occasional Contributor II

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.

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

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.



Think Location
0 Kudos
DitlevReventlow
Occasional Contributor II

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 >=. 

0 Kudos