Dear GIS experts.
I can't get my raster calculator expression to run.
I have two different raster datasets:
- wnb_near
- svo_near
I want to create a new raster. When the value of svo_near ist smaller than the value of wnb_near, I want to write the value of wnb_near in the new raster, otherwise the value of svo_near:
if svo_near < wnb_near, then wnb_near, else svo_near
I tried the following expression in the raster calculator:
Con("svo_near" < " wnb_near", "wnb_near", "svo_near")
It doesn't work...
The two raster datasets are attached. Could somebody please help? Thanks a lot!
Barbara
Solved! Go to Solution.
Interesting question and great answers by everybody.
As @Robert LeClair said, there are many ways to solve this problem. So, instead of getting into the solutions presented here, I would like to point out a few different things that could be relevant for getting the output @Barbara is looking for.
The Con Statement and the use of quotation:
Con("svo_near" < "wnb_near", "wnb_near", "svo_near")
This statement is valid in Raster Calculator. (@Barbara Please note there is an extra space between " and the letter w in your statement, but I guess that's a typo).
However, if you want to execute this statement in Python window, or in a standalone python script, you need to cast your dataset as a raster as follows.
Con(Raster("svo_near") < Raster(" wnb_near"), "wnb_near", "svo_near")
It was not clear to me what exactly @Barbara meant by "it doesn't work", but I can see the problem in the Con output could happen for many reasons:
(1) The extent of these datasets are different
(2) The origin (lower-left) corners are different, may lead to cell misalignment between these two datasets
(3) The existence of NoData in both datasets (where one dataset has value and the other one has NoData).
From the dataset properties I can see:
wnb_near
Bottom: 1,225,582.880500
Letf: 2,671,897.064800
Columns: 4494
Rows: 5592
Cellsize: 10
svo_near
Bottom: 1,226,215.736100
Letf: 2,671,630.064800
Columns: 3431
Rows: 5425
Cellsize: 10
Analysis Environment
Since, I don't know which dataset extent is important for @Barbara, I am going to make the following assumptions for my analysis environment.
Extent: Union of Inputs
Cell Size: Same as wnb_near
Snap Raster: Same as wnb_near
Problem Statement
It seems like @Barbara is trying to get the maximum value of the two datasets (wnb_near and
svo_near) in the output.
If that is correct, I can use the Cell Statistics tool to solve this problem. Why Cell Statistics? Because this tool has an option to ignore NoData during analysis, which will become really handy in this situation.
Please note, all other approaches are valid and will produce accurate results as long as we take care of the extent, cell alignment and NoData.
Analysis
(1) Set analysis environment as stated above
(2) Run Cell Statistics tool with Maximum as Overlay Statistics
Analysis Output
I named this output as max_wnb_svo. The output cover the extent of both datasets and carried over cell values from both inputs by ignoring NoData.
@Barbara, is this what you are looking for?
Inputs
Please notice the different in extent and origin.
wnb_near
svo_near
Conclusion
I may misunderstood the original problem stated by @Barbara and therefore, the output I created may not what @Barbara is looking for.
However, I wanted to highlight the importance of the analysis extent and the cell alignment for any raster analysis and the need of using Raster object in any map algebra expression outside of Raster Calculator. Also wanted to point out the "Ignore NoData in calculations" option in the Cell Statistics tool, which becomes really handy in cases like this.
I hope, by considering all these, and all the other analytical options presented by others @Barbara will be able to create the appropriate output.
Thanks,
Noman
Esri, Redlands, California
The raster names shouldn't be in quotes if they are variable names
I don't see anything wrong with the statement, as it's in Raster Calculator not map algebra, the quotes are needed.
I would troubleshoot by performing some simple expressions on each raster to see if the rasters themselves are the issue.
Never use the raster calculator
Anyway, I used the Combine tool to come up with a raster that you can reclassify.
You can see where wbn_near class 3 matches svo_near for 4567 cells, so that become the basis for the reclass
This would probably easier since you have a lot of areas don't overlap
Barbara - so one of the problems I came across with the rasters and the raster calculator had to do with NULL values in the raster dataset. Whenever I tried to do raster math the NULL values would mess with the output. So here's the workflow I used to get what I think is the correct approach (I could be wrong!)
With the new output raster dataset (rascal5), I did a few cell evaluations and it seemed to process correctly.
Let me know what you discover.
why is why combine then a reclass might be easier
Possibly - many ways to accomplish the same task I always say.
Interesting question and great answers by everybody.
As @Robert LeClair said, there are many ways to solve this problem. So, instead of getting into the solutions presented here, I would like to point out a few different things that could be relevant for getting the output @Barbara is looking for.
The Con Statement and the use of quotation:
Con("svo_near" < "wnb_near", "wnb_near", "svo_near")
This statement is valid in Raster Calculator. (@Barbara Please note there is an extra space between " and the letter w in your statement, but I guess that's a typo).
However, if you want to execute this statement in Python window, or in a standalone python script, you need to cast your dataset as a raster as follows.
Con(Raster("svo_near") < Raster(" wnb_near"), "wnb_near", "svo_near")
It was not clear to me what exactly @Barbara meant by "it doesn't work", but I can see the problem in the Con output could happen for many reasons:
(1) The extent of these datasets are different
(2) The origin (lower-left) corners are different, may lead to cell misalignment between these two datasets
(3) The existence of NoData in both datasets (where one dataset has value and the other one has NoData).
From the dataset properties I can see:
wnb_near
Bottom: 1,225,582.880500
Letf: 2,671,897.064800
Columns: 4494
Rows: 5592
Cellsize: 10
svo_near
Bottom: 1,226,215.736100
Letf: 2,671,630.064800
Columns: 3431
Rows: 5425
Cellsize: 10
Analysis Environment
Since, I don't know which dataset extent is important for @Barbara, I am going to make the following assumptions for my analysis environment.
Extent: Union of Inputs
Cell Size: Same as wnb_near
Snap Raster: Same as wnb_near
Problem Statement
It seems like @Barbara is trying to get the maximum value of the two datasets (wnb_near and
svo_near) in the output.
If that is correct, I can use the Cell Statistics tool to solve this problem. Why Cell Statistics? Because this tool has an option to ignore NoData during analysis, which will become really handy in this situation.
Please note, all other approaches are valid and will produce accurate results as long as we take care of the extent, cell alignment and NoData.
Analysis
(1) Set analysis environment as stated above
(2) Run Cell Statistics tool with Maximum as Overlay Statistics
Analysis Output
I named this output as max_wnb_svo. The output cover the extent of both datasets and carried over cell values from both inputs by ignoring NoData.
@Barbara, is this what you are looking for?
Inputs
Please notice the different in extent and origin.
wnb_near
svo_near
Conclusion
I may misunderstood the original problem stated by @Barbara and therefore, the output I created may not what @Barbara is looking for.
However, I wanted to highlight the importance of the analysis extent and the cell alignment for any raster analysis and the need of using Raster object in any map algebra expression outside of Raster Calculator. Also wanted to point out the "Ignore NoData in calculations" option in the Cell Statistics tool, which becomes really handy in cases like this.
I hope, by considering all these, and all the other analytical options presented by others @Barbara will be able to create the appropriate output.
Thanks,
Noman
Esri, Redlands, California
Dear GIS experts
Thank you! I'm very thankful for your help and the time you put in your answers! With your help it works.
Stay well and again thanks a lot
Barbara