I am trying to figure out proper solution to combine >100 raster images. These raster images are individual animal utilization distributions (values 0-1) that are modeled using dynamic brownian bridge movement models in package move. What I'd like to do now is find an appropriate way of combining individual animal UDs to create a "population-level" distribution. See below for code.

# Libraries


# Import raster files from a single folder as a list 
raster_list <- as.list(dir(path = 'Results/TN/', pattern = '.tif$', 
                       all.files = TRUE, 
                       full.names = TRUE))

# Make them rasters
raster_list <- lapply(raster_list, raster)

# Function to get max extent of list of rasters
extend_all <- function(rasters){
  extent(Reduce(extend, rasters))

# Get max extent of raster list
max_extent <- extend_all(raster_list) #[which(!is.na(x))])

# Make an empty raster that will be used as mask 
mask.raster <- raster()

# Set "max" extent of mask 
extent(mask.raster) <- max_extent   

# Set resolution to 10000 m 
res(mask.raster) <- 10000

# Make lat/long projection 
projection(mask.raster) <- CRS("+proj=aeqd +ellps=WGS84")

# Set all values of mask.raster to zero
# Bilinear resampling for all birds that aren't NAs based on mask extent
mask.raster[] <- 0
re <- lapply(raster_list[which(!is.na(raster_list))], function(r){
  resample(r, mask.raster, method = "bilinear")

# Stack rasters
raster_stack <- stack(re)

# Merge rasters
raster_merge <- do.call(raster::merge, re)

I thought, by simply merging rasters I could generate the desired output but apparently not, and presumably because of the way the rasters are ordered. For example, here is a picture of the first raster plot(re[[1]])

enter image description here

And here is a picture of the "merged" raster plot(raster_merge); they're virtually identical, which I know doesn't make sense.

enter image description here

because here's a UD from the second raster layer in the list plot(re[[2]])

enter image description here

Is there a different way to merge these rasters together to create population-level UD?

1 Answer 1


I think you need to do a bit more work on the UD rasters that you have before merging them.

Currently, your issue seems to arise from your rasters not being adequately subset to a desired probability before you go to merge them.

Below is how I would start to do this for the leroy dataset from {move}. I have borrowed heavily from Chapter 8 in the Using the move package vignette. If you are interested, we could probably adapt this into a good reprex for your question, but if you haven't already, you should go there for more:


#example data    
leroy.prj<-spTransform(leroyRed, center=TRUE)
dBB.leroy <- brownian.bridge.dyn(leroy.prj, ext=.85, raster=100, location.error=20)
# class      : DBBMM 
# dimensions : 145, 181, 26245  (nrow, ncol, ncell)
# resolution : 100, 100  (x, y)
# extent     : -9048.876, 9051.124, -7249.391, 7250.609  (xmin, xmax, ymin, ymax)
# crs        : +proj=aeqd +lat_0=42.73728285 +lon_0=-73.8845778 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs 
# source     : memory
# names      : layer 
# values     : 0, 0.1260549  (min, max)

#produce a UD similar to the one in your example:

enter image description here

#extract the area with a given probability, where cells that belong to the given probability will get the value 1 while the others get 0:
ud95 <- UDleroy<=.95
plot(ud95, main="UD95")

enter image description here

#produce a UD that mantains the lower probabilities:
ud95 <- UDleroy
ud95[ud95>.95] <- NA
plot(ud95, main="UD95")

enter image description here I think your issue with the rasters overlapping one another will persist when you go to merge them so use caution. The above methods should only be used for rasters that do not overlap or where you’re only concerned with displaying one specific probability all at once.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.