# NOT RUN {
library(raster)
r <- raster(ncol=100,nrow=100)
r[] <- sample(c(0,1), ncell(r), replace = TRUE)
majority <- function(x){
m <- table(x)
names(m)[which.max(m)][1]
}
r <- focal(r, matrix(1,11,11, byrow=TRUE), majority)
pts <- rasterToPoints(r, spatial=TRUE)
cls <- pts[pts$layer == "1",]
d <- rasterDistance(pts, cls, reference = r, scale=TRUE)
dev.new(height=8,width=11)
plot(d)
points(cls,pch=19,cex=0.5)
# }
Run the code above in your browser using DataLab