a simple question on raster calculator

2365
11
10-16-2014 01:24 AM
giuseppeprocino
New Contributor II

Dear all,

I have two raster with same area, extent and cell value:

- rasterA with only 0-1 value.

- rasterB with only 0-1,255 and null value.

 

I would obtain a third raster (rasterC) where if rasterA contain the value 1 and the rasterB contain the value 0 (for the same cell position) rasterC must contain the value 1. If the previous condition is false the value for the rasterC will be the same of rasterB.

 

How I can perform this condition within raster calculator in ArcGIS Desktop?

 

Giuseppe P.

0 Kudos
11 Replies
DanPatterson_Retired
MVP Emeritus

You want the Con statement in the spatial analyst.  You can build the syntax you want, but make sure that you pay attention case-sensitivity of the statements and the use of brackets.  here are examples

Con("grid1" < 2, 0, Con("grid1" < 3, 1, ("grid1" - 1) / 4.0))

Con(("polynom2" == 5)  & ("logistic" == 5), 1, 0)

in your case it might be

Con(("rasterA" == 1)  & ("rasterB" == 0), 1, 0)

but I haven't tested

0 Kudos
giuseppeprocino
New Contributor II

Hi Dan,

Con(("rasterA" == 1)  & ("rasterB" == 0), 1, 0).

I tried the following statement:Con(("rasterA" == 1)  & ("rasterB" == 0), 1, "rasterB").

but it doesn't work how I would like.

An example of my input raster (rasterA and rasterB) and the rasterC that I would obtain.

rasterA                    rasterB                             rasterC

010null11null11
10025502552550255
11100null11null

Giuseppe

0 Kudos
DanPatterson_Retired
MVP Emeritus

I am surprised that the null values were even considered...on well

Con(("rasterA" == 1)  & ("rasterB" == 0), 1, "rasterB").

0 Kudos
giuseppeprocino
New Contributor II

The result is wrong with the statements:

Con(("rasterA" == 1)  & ("rasterB" == 0), 1, "rasterB").

or

Con(("rasterA" == 1)  & ("rasterB" == 0), 1, 0).

0 Kudos
DanPatterson_Retired
MVP Emeritus

show the results then as well as the input...I have nothing to test against, so I am going by instinct

0 Kudos
giuseppeprocino
New Contributor II

Hi Dan,

no problem but I'm still looking a solution .

0 Kudos
FlorianHoedt1
New Contributor II

I dont see an error here. You described:

I would obtain a third raster (rasterC) where if rasterA contain the value 1 and the rasterB contain the value 0 (for the same cell position) rasterC must contain the value 1. If the previous condition is false the value for the rasterC will be the same of rasterB.

which translates to this pseudocode (C#):

if ( rasterA == 1 && rasterB == 0)

{

     rasterC = 1;

}

else {

     rasterC = rasterB;

}

if rasterB is null it is not 0 therefore rasterC will be filled with rasterB value (null).

Which brings me to this question: What value do you want to get inserted in rasterC if rasterB has a null value?

0 Kudos
giuseppeprocino
New Contributor II

Hi Florian,

your pseudocode in C# is exactly what I want.

What value do you want to get inserted in rasterC if rasterB has a null value?

I want preserve null value.

0 Kudos
FlorianHoedt1
New Contributor II
0 Kudos