# Raster calculator to create single raster with 4 values from two binary rasters

I have two binary rasters showing habitat suitability (0 = unsuitable, 1 = suitable) under current and future climate scenarios. I am trying to create a raster showing:

0 = cells that are not suitable under either scenario (i.e. = 0 in both rasters) 1 = cells suitable under current (=1) but NOT future (=0) 2 = cells suitable under both scenarios (i.e. both = 1) 3 = cells suitable under future (=1) but not current (=0)

So the final raster will consist of values of 0 , 1 , 2, 3, 4 (and no data = -9999)

I am struggling with the correct syntax in raster calculator. Is it possible to do this all in one line of syntax or do I have to create four separate rasters?

To summarise my files:

I have a current binary raster (Model10a_bin.tif) and a future binary raster (Model10a_yr2050_bin.tif) and I am trying to create a new raster showing the following:

If Model10a_bin.tif = 0 and Model10a_yr2050_bin.tif = 0 ; Value new raster = 0

If Model10a_bin.tif = 1 and Model10a_yr2050_bin.tif = 0 ; Value new raster = 1

If Model10a_bin.tif = 1 and Model10a_yr2050_bin.tif = 1 ; Value new raster = 2

If Model10a_bin.tif = 0 and Model10a_yr2050_bin.tif = 1 ; Value new raster = 3

• I guess you forgot to mention what software you're talking about (add a tag too). Commented Jan 21, 2015 at 17:09
• I don't see how you will ever get a value of 4. If you are willing to change your coding a little you can obtain the result easily by adding twice the future raster to the current raster: this would swap the meanings of "2" and "3". If you need these codings, the same approach will work after complementing the future raster (by applying "not" or subtracting it from 1). But as far as syntax goes, you will need to tell us more about what GIS platform you are using, right down to the exact version and how you invoke its raster calculator. Commented Jan 21, 2015 at 18:16
• Sorry - yes ArcMap / Catalog 10.2 on Windows 8.1 Commented Jan 21, 2015 at 21:16

Assuming ArcGIS use combine, e.g.

``````Combine (["a.tif","b.tif"])
``````

Combines multiple rasters so that a unique output value is assigned to each unique combination of input values

• Thank you very much, this is exactly what I needed and a very useful tool Commented Jan 23, 2015 at 16:09

You could reclass one of the rasters so that your binary values are:

``````|Raster                  |Yes Value  |No Value   |
+------------------------+-----------+-----------+
|Model10a_bin.tif        |1          |0          |
+------------------------+-----------+-----------+
|Model10a_yr2050_bin.tif |2          |0          |
``````

Then simply add the two together so the outputs of the new raster would be:

``````|Output            |Value  |
+------------------+-------+
|No + No (0, 0)    |0      |
+------------------+-------+
|Yes + No (1, 0)   |1      |
+------------------+-------+
|No + Yes (0, 2)   |2      |
+------------------+-------+
|Yes + Yes (1, 2)  |3      |
``````

Slightly different than your breakdown, but similar results.

• Yes, thank you, eventually worked out that reclassifying is the easiest way forward, just with slightly different class values, followed by adding the two together. Commented Jan 21, 2015 at 21:16

with the raster calculator, you can use conditions to get exactly what you need :

``````Con("Model10a_bin.tif" == 0, Con("Model10a_yr2050_bin.tif" == 0, 0, 3), Con("Model10a_yr2050_bin.tif" == 0, 1, 2))
``````

another single line algebra, shorter to write, is the sum of the first with the double of the second. But 2 and 3 are then inverted

``````"Model10a_bin.tif" + 2*"Model10a_yr2050_bin.tif"
``````
• Thank you very much - this is exactly what I was trying to do but can be easily achieved using "combine" as suggested below. Thanks for your help everyone Commented Jan 23, 2015 at 16:10