Efficiently replacing target landcover class with neighbourhood majority class

Discussion created by malnunn on Feb 16, 2014
Latest reply on Feb 18, 2014 by bsriramak

I have a soil type classification that has 8 classes: 7 soil classes and water. For the purposes of feeding the soil type layer into a model, I need to eliminate the water class and replace it with the existing (nearby) soil types. I've been attempting to do this by 'growing out' the majority soil type in the neighbourhood surrounding the water pixels.

My current thinking for doing this is to run a script iteratively that produces a focal statistics raster then run a Con statement, to replace any water pixel with the neighbourhood majority.

# Input soil type raster
ras1 = arcpy.Raster(r"C:\spatial_data\soils.gdb\soiltype")

# Produce a focal statistics raster that takes the majority value in a circle (radius = 5)
focal_ras = sa.FocalStatistics(ras1, sa.NbrCircle(5), "MAJORITY")

# if the pixel is water (VALUE == 6), use the neighbourhood majority statistic
out_ras = sa.Con(ras1 == 6, focal_ras, ras1)

This erodes the edges of rivers and lakes very slowly however, since the pixels towards the centre will have water as the majority. If I make all the water NoData first, and change the Con statement to:
out_ras = sa.Con(sa.IsNull(ras1), focal_ras, ras1)

then it works much faster, however as my area of interest is an island, this also results in my entire raster 'growing' into the NoData ocean around it (island).

I'm sure what I'm doing is horribly inefficient and poor practice. Can anyone advise on a better way of achieving this simplistic replacement of a class?