[tlocoh-info] problem in converting isopleths to rasters

g.cerritelli giulia.cerritelli at biologia.unipi.it
Tue Apr 20 10:20:14 CEST 2021


Hi all,

I have a question on converting isopleths to rasters using the function 
lhs.iso.rast.
My final goal is to evaluate the percentage of overlap between animals 
home range for which I would like to use the function kerneloverlap in 
adehabitatHR. To this aim I need to convert the isopleths of all animals 
using the same raster for all animals as grid. I have tried to use the 
function lhs.iso.rast setting in the function arguments a raster layer 
as grid, but I get an error I don't know how to solve. I would really 
appreciate if anyone can give me some suggestions on how to solve the 
problem.
Here I have reported an example:

##Create the locoh-xy and select one ID
utm.lxy <- xyt.lxy(xy = coordinates(data.utm), dt=NULL, id= data.utm$ID, 
proj4string=CRS("+proj=utm +zone=32 +ellps=intl +units=m +no_defs"))
lxy_89 <- lxy.subset(utm.lxy, id = "3")

##I use the a-method and select the best values (I have not reported 
here all the selection procedures) and then I finally obtain the lhs 
object
89.lhs.a <- lhs.select(89.lhs.amixed, a=160000)

##I create a SpatialPixel that I then transform to raster
> x <- seq(519000, 791000, by=500) # resolution is the pixel size you 
> desire (500 m)
> y <- seq(4500000, 4900000, by=500)
> xy <- expand.grid(x=x,y=y)
> coordinates(xy) <- ~x+y
> gridded(xy) <- TRUE
> class(xy)
[1] "SpatialPixels"
attr(,"package")
[1] "sp"

> r <- raster(xy)
> proj4string(r) = proj4string(data.utm)
> r
class      : RasterLayer
dimensions : 801, 545, 436545  (nrow, ncol, ncell)
resolution : 500, 500  (x, y)
extent     : 518750, 791250, 4499750, 4900250  (xmin, xmax, ymin, ymax)
crs        : +proj=utm +zone=32 +ellps=intl +units=m +no_defs

##I try to convert the isopleths to raster, and here I get the error
> SCOLA_89.lhs.a <- lhs.iso.rast(SCOLA_89.lhs.a, raster = r, status=TRUE)
Converting isopleths to rasters
3.pts812.a160000.s0.kmin0
Error in round(nrows) : non-numeric argument to mathematical function


##Note: If I use just the cell size as argument, the function correctly 
transforms the isopleths, thus I don't think it is a problem in the lhs 
object
> SCOLA_89.lhs.a <- lhs.iso.rast(SCOLA_89.lhs.a, cell.size=100, 
> status=TRUE)
Converting isopleths to rasters
3.pts812.a160000.s0.kmin0
   
|=================================================================================| 
100%
Total time: 3.4 secs


Thank you in advance for any help you can provide

Best,
Giulia





More information about the Tlocoh-info mailing list