Using Arc 10.2.2 with Spatial Analyst, I need to determine the spatial intersection of two rasters (both rasters are in the same coordinate system, and are aligned to the same snap raster). The two rasters have different values.
Specifically, I want to determine which cells are occupied by both raster A and raster B.
Here's my method, using the Raster Calculator:
- I create an intermediate raster each for raster A and B, calculating the output to the value 1. This identifies, for each raster, which cells are occupied:
intermediate_A = (A * 0) + 1
intermediate_B = (B * 0) + 1
- Add the two intermediate rasters together:
final_output = intermediate_A + intermediate_B
The final_output raster will have the value 2 for the intersecting cells, otherwise NoData.
Everything seems to work correctly. However, I'm wondering if there's a more efficient way to determine the spatial intersection with fewer steps or without creating the intermediate rasters?
-
1Con( ~IsNull("A" + "B"),1)FelixIP– FelixIP2015年12月09日 19:08:33 +00:00Commented Dec 9, 2015 at 19:08
1 Answer 1
Try:
Con(((IsNull(A))|(IsNull(B))),0,1)
If either A or B are null it will give you 0 if not 1, all the ones should show where A and B have values.
-
1Excellent! After a little investigation, I confirmed that additional rasters can be easily tested by simply extending your equation. For example, to determine those cells where three rasters (A, B, C) intersect: Con(((IsNull(A))|(IsNull(B))|(IsNull(C))),0,1)Stu Smith– Stu Smith2015年12月10日 21:38:52 +00:00Commented Dec 10, 2015 at 21:38
-
great! @FelixIP's code is even shorter and does the same thing. I always forget to use the '~'. He took advantage of the fact that any operation with a nodata cell will always become nodata, so even if, only one raster has no data at that location when you add it with another that has value, it just becomes 'nodata'. A great alternative workaroundyanes– yanes2015年12月11日 20:31:58 +00:00Commented Dec 11, 2015 at 20:31
-
Ooop, @Felix, sorry thst I missed your answer; it was so short and succinct!Stu Smith– Stu Smith2015年12月11日 20:59:17 +00:00Commented Dec 11, 2015 at 20:59
Explore related questions
See similar questions with these tags.