0

I ran some species distribution models (SDM), using maxent of the 'dismo' package for several species, so I saved each one as a raster file.

After that I transformed this environmental suitability raster (SDM result) into a binary map based on a determined threshold value.

I used this function and these command lines to do the conversion:

bin <- function(x) {
   ifelse(x <= 0.7, 0,
   ifelse(x > 0.7, 1, NA)) }
sp_bin <- calc(spp, fun=bin) # "spp" is the object within my raster
writeRaster(sp_bin,filename='Results/RasterBin/Patagioenas_fasciata_bin.tif')

Now I have a raster of that binary map (i.e., with only two values, 0 and 1).

class       : RasterLayer 
dimensions  : 1117, 1576, 1760392  (nrow, ncol, ncell)
resolution  : 0.008333333, 0.008333333  (x, y)
extent      : -68.39167, -55.25833, -0.7333333, 8.575  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : C:\Users\Ramiro\Desktop\SDM\Results\RasterBin\Patagioenas_fasciata_bin.tif 
names       : Patagioenas_fasciata_bin 
values      : 0, 1  (min, max)

I tried to use the following argument to bring the sum of the pixels with value 1, assuming that the others would be 0 and therefore the total sum would equal the area of all pixels with values 1:

cellStats(spp, stat='sum', na.rm=TRUE)

And I got a numerical result (12,471) that I thought was correct. However, I did this for other species, and therefore other rasters, and the result remains the same, although each species has a distinct binary map.

How can I calculate the area only for pixels with value "1" in a binary map raster in R?

Thank you all for the attention.

  • To get the number of pixels of your class you could use `sum(spp[]==1)`. Given your pixel resolution, you can then calculate the area. – Val May 07 '17 at 09:06
  • FYI you should be able to do away with your `bin` function and just do `spp >= 0.7` (or `as.integer(spp >= 0.7)`) to return a binary `Raster*` object. – jbaums May 09 '17 at 12:08

0 Answers0