Search code examples
rarcgisarcpy

Is there an R function equivalent to FuzzyOverlay( ,"AND") in ArcPy?


I am transferring a suitability model from arcpy into R, and am trying to find a function or package that performs a fuzzy overlay similar to FuzzyOverlay. What R operations would produce the same output as the fuzzyOverlay( , "AND") function in ArcPy?

My model produces intermediary raster layers with 0-100 values, which I am attempting to overlay through fuzzy membership

I've tried fuzzySim::fuzzyOverlay, but am not certain if these perform the same operation. My model inputs had values of 0-100, which ran fine in arcpy fuzzyOverlay, but fuzzySim::fuzzyOverlay gave an error until I rescaled values to 0-1. An attempt at reproducible code is below, but again, not certain if this is the function to be using.

#make 4 rasters
r1 <- raster(xmn = -100, xmx = -60, ymn = 25,  ymx = 50,  res = c(1,1)) 
r2 <- r1
r3 <- r1
r4 <- r1

#fill with random values
r1[] <- runif(ncell(r2), 0, 1)
r2[] <- runif(ncell(r2), 0, 1)
r3[] <- runif(ncell(r3), 0, 1)
r4[] <- runif(ncell(r3), 0, 1)

#stack rasters
rs <- stack(r1, r2, r3, r4)

#perform fuzzyOverlay
xy <- fuzzyOverlay(rs, op = "fuzzy_and")

I want an output that returns, per ESRI's description, "the minimum of the fuzzy memberships from the input fuzzy rasters", ideally in raster format. Am I on the right track?


Solution

  • Given the discriptions fuzzyAndValue = min(arg1, ..., argn)I think that is just a simple min function:

    #make 4 rasters
    r1 <- raster(xmn = -100, xmx = -60, ymn = 25,  ymx = 50,  res = c(1,1)) 
    r2 <- r1
    r3 <- r1
    r4 <- r1
    
    #fill with random values
    r1[] <- runif(ncell(r2), 0, 1)
    r2[] <- runif(ncell(r2), 0, 1)
    r3[] <- runif(ncell(r3), 0, 1)
    r4[] <- runif(ncell(r3), 0, 1)
    
    #stack rasters
    rs <- stack(r1, r2, r3, r4)
    
    #perform fuzzyOverlay
    xy <- min(rs)
    plot(xy)