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.
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
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
0 | 1 | 0 | null | 1 | 1 | null | 1 | 1 | ||
1 | 0 | 0 | 255 | 0 | 255 | 255 | 0 | 255 | ||
1 | 1 | 1 | 0 | 0 | null | 1 | 1 | null |
Giuseppe
I am surprised that the null values were even considered...on well
Con(("rasterA" == 1) & ("rasterB" == 0), 1, "rasterB").
The result is wrong with the statements:
Con(("rasterA" == 1) & ("rasterB" == 0), 1, "rasterB").
or
Con(("rasterA" == 1) & ("rasterB" == 0), 1, 0).
show the results then as well as the input...I have nothing to test against, so I am going by instinct
Hi Dan,
no problem but I'm still looking a solution .
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?
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.