Skip to main content
Question Protected by CommunityBot
edited tags
Link
whuber
  • 70.2k
  • 16
  • 187
  • 282
Tweeted twitter.com/#!/StackGIS/status/376137644226674688
Source Link
Conor
  • 3k
  • 2
  • 17
  • 44

Efficiently check for equal adjacent values in raster calculator

I have a raster consisting of integer values in each cell. I want to check every adjacent cell in a 3x3 grid to see if any one of the adjacent cells has a value EQUAL to the center cell, and if so, give the output raster a value of 1 (else give it a value of 0). I have already accomplished this like so:

Con("raster" == FocalStatistics("raster", NbrIrregular("C:\filepath\kernel_file.txt"), "MAXIMUM"), 1, 0)

Where the kernel file looks like this:

3 3 
1 0 0
0 0 0
0 0 0 

Then again for another possible combination:

3 3 
0 1 0
0 0 0
0 0 0

And so forth:

3 3 
0 0 1
0 0 0
0 0 0 

Then I have to combine all of the rasters at the end to get one final raster.

Is there a more efficient way to accomplish this? It shouldn't be necessary to loop through the raster this many times to get what I need. Raster calculator solutions will work, but ArcObjects solutions are welcome as well as the end result will likely end up being implemented in ArcObjects.