3

I need to build a raster based on 8 raster layers.

Data in these 8 layers are divided into 3 classes, (1) K (values 1-1.5), (2) V (values 2-4) and (3) Z (values 5-12). The new raster is raster K, and for each cell I want to count how many times K occurs in the corresponding cell in the rasters below (later, I want to do the same for V and Z). The number of cells belong to this class should be the cell value in the new raster.

It is not my goal to add the values, just count how many cells belong to a certain class.

I have been searching in the ArcToolbox, but I cannot seem to find a tool that does this. Can anyone help me? I am very unfamiliar with scripting.

I am using Using ArcGIS 10.2.1

2
  • Your request is vague, because (1) you refer to both a class and raster by the same name, "K"; (2) you distinguish one raster "K" as being "new" without explaining what that means for this procedure; and (3) you have not explained what it means by a raster to be "below" another. Could you please clarify these points?
    – whuber
    Oct 23, 2014 at 18:43
  • Hopefully this clarifies the question: (1) raster K should be the output raster, which counts the number of times class K is present in the input rasters - I guess for clarity the output raster should be called Kn; (2) by new I mean the output raster, it did not exist before, I don't know how else to state this; (3) by rasters 'below' I mean the input rasters.
    – Renée
    Oct 27, 2014 at 8:13

2 Answers 2

5

The easiest way to do this without scripting would be to use the Con tool in modelbuilder (spatial analyst licence needed!). Con lets you define a condition (e.g. VALUE >= 1 and VALUE <= 1.5) and outputs a raster with value 1 for where the condition is true and 0 where the condition is false. If you do this for every raster you can then add all (plus) these output rasters together this will give you your K raster with for every cell the frequency of K values in the other 8 rasters. Repeat for your V and Z values. The model should look something like this:

enter image description here

2
  • Using con and plus seems like the way to go, but I think it is rather time consuming as you have to build or use the con and plus section of the model multiple times (both 8 times). I found a different solution: all 'con' operations I did in batch mode, and then I used the raster calculator to add all resulting rasters. Thanks for your help!
    – Renée
    Nov 5, 2014 at 7:57
  • Good stuff, I seem to forget about the existence of Raster calculator sometimes, but it's perfectly suited for this indeed. Glad I could help!
    – Menno
    Nov 5, 2014 at 10:28
2

Because there are more rasters than classifications, it would be expedient to use procedures that handle the rasters as a group rather than having to process them one by one. A built-in command, Less than Frequency, exists to do precisely that:

  • The number of rasters classified as "K" is the number less than 2, given with an expression like

    Q2 = LessThanFrequency(2, ["Input raster 1", "Input raster 2", ..., "Input raster 8"])
    

    Of course the "..." has to be replaced by explicit mentions of the other rasters. However, the order in which the rasters are named does not matter.

  • The number of rasters classified as "K" or "V" is the number less than 5, given with an expression like

    Q5 = LessThanFrequency(5, ["Input raster 1", "Input raster 2", ..., "Input raster 8"])
    

    Notice that this is achieved with a simple cut-and-paste of the expression for "Q2", changing the "2" to a "5".

  • The number of rasters classified as "K" or "V" or "Z" should not be assumed to equal 8 (unless you are absolutely sure there are no NoData cells and all values truly are less than 12). Instead, keep up the preceding pattern. Since the help page examples indicate LessThanFrequency uses a strict comparison--equalities are not included--consider making a comparison with a threshold slightly greater than 12, as in

    Q13 = LessThanFrequency(13, ["Input raster 1", "Input raster 2", ..., "Input raster 8"])
    

After these three calculations you can obtain the individual class counts via subtraction, as in

V = "Q5" - "Q2"
Z = "Q13" - "Q5"

K, of course, is simply "Q2" (provided you are sure the input values are always 1 or greater and never lie between 1.5 and 2).


Looking back, it is evident that in general you can count m interval-based classes in a set of m rasters by means of m applications of LessThanFrequency followed by m-1 differences. When n is larger than 2 * m, this will be one of the most efficient methods you can apply. In any case it is very clear procedure, easy to write and easy to verify.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.