2

I have animal tracking data in the form of a SpatialPointsDataFrame. Aside from xy coordinates, this data frame contains 2 variables, "animalID" and "date" (in the form "yyyy-mm-dd hh:mm:ss"). For each animal, there are hundreds of points, and the the total number of points for each animal is not equal.

I would like to create raster where each grid cell contains a value for the "proportion of time spent in the cell". This would be calculated for each animalID, and is equal to "the number of points in that cell, divided by the total number of points for that animal"

I know how to assign points to a raster grid (code below). But I don't know how to assign points to a grid for each animalID. Once I accomplish this, I then (for each animalID) need to divide the value of each cell by the total number of points for that animalID. How could I do this?

r<-raster(temp) #create a blank raster with the same extent as my temperature raster
r[] <- 0
r

#populate this new raster with the animal location data
tablepoints <- table(cellFromXY(temp, animallocations)) 
tab<-as.data.frame(tablepoints) 
r[as.numeric(names(tablepoints))] <- tablepoints
r

Here is example raster and SpatialPointsDataFrame.

library(raster)
library(sp)
library(rgdal)
r <- raster(xmn=0, ymn=0, xmx=10, ymx=10, res=1)
r[] <- 0
id<-as.data.frame(c(rep("bird1",80), rep("bird2",50), rep("bird3",70)))
colnames(id)[1]<-"animalID"
xy<-spsample(as(extent(r), 'SpatialPolygons'), 200, 'random')
data<-SpatialPointsDataFrame(xy, id)

Ideally, I would like 1 raster, where each cell has three variables: proportion for bird1, proportion for bird2, and proportion for bird3

Splash1199
  • 379
  • 3
  • 14

0 Answers0