[AniMov] Re: adehabitat-GRASS

Clément Calenge calenge at biomserv.univ-lyon1.fr
Mon Jun 27 17:16:24 CEST 2005


Dear all,

>I'm testing the new R-GRASS6 interface (spgrass6) of Roger Bivand and it works 
>well with raster and vector too.
>I see that to move a vector from GRASS to R or viceversa it uses shapefiles.
>In adehabitat "kernelUD" is the most powerful function and the correlated 
>function "getverticeshr" allows to estimate the Kernel Home-Range in 
>percentage and it returns a polygon object of class kver.
>
>The structure of an object of class kver is the follow:
>str(ver)
>List of 1
> $ Brock:Classes area  and `data.frame':        120 obs. of  3 variables:
>  ..$ id: Factor w/ 1 level "1": 1 1 1 1 1 1 1 1 1 1 ...
>  ..$ x : num [1:120] 698626 698670 698714 698758 698802 ...
>  ..$ y : num [1:120] 3160417 3160417 3160417 3160417 3160417 ...
>
>Would it be possible to convert it in a shapefile to import it in GRASS?
>In this way, it will be possible develop a large range of analysis between the 
>home range and the structure of the territory in GRASS.
>  
>

I don't know well the GRASS software. However, I know the sp package,
and it is easy to convert the object of class "kver" into a list of objects
of class "SpatialRings"

library(adehabitat)
data(puechabon)
loc <- puechabon$locs[, c("X", "Y")]
id <- puechabon$locs[, "Name"]
ud <- kernelUD(loc, id)
 
## Calculation of the 95 percent home range
ver <- getverticeshr(ud, 95)
plot(ver)

## ver is a list of objects of class "area".
## There is now a function in adehabitat
## which allows the conversion to the
## classes of the package sp (see the
## help page of area2sr (the package
## sp is needed):

oo <- lapply(ver, area2sr)

## oo is a list of objects of class "SpatialRings".
## It is possible to convert each
## element of this list into a "shapefile" format,
## but before, we have to convert
## each object to the class "SpatialRingsDataFrame":

kk<-lapply(oo, function(x) SpatialRingsDataFrame(x,
           data.frame(name=as.character(1:length(x at polygons)))))

## install the package spmaptools
rSpatial <- "http://r-spatial.sourceforge.net/R"
install.packages("spmaptools", repos=rSpatial)
library(spmaptools)

## creates the lists of names of files
name <- names(ver)

## and export to shapefile
lapply(1:length(kk),
       function(i) writeSRDFShape(kk[[1]], name[i]))


That's all, the shapefiles are available in your working directory.

>An other way would to convert the result of getvolumeUD (a grid where the 
>value cell describe the home ranges estimated at different probability 
>levels) in a SpatialGridDataFrame and then move it in GRASS.
>  
>
Even easier to do:

## Loads the data
library(adehabitat)
data(puechabon)
loc <- puechabon$locs[, c("X", "Y")]
id <- puechabon$locs[, "Name"]
el <- getkasc(puechabon$kasc, 1)


## we use here the same grid for all
## animals (el) to fit the UD

ud <- kernelUD(loc, id, grid = el)
vud <- getvolumeUD(ud)

## Conversion to the class kasc:
li <- lapply(vud, function(x) x$UD)
names(li) <- names(vud)
kasc <- as.kasc(li)
image(kasc)

## conversion to SpatialPixelDataFrame
res <- kasc2spixdf(kasc)
image(res)

After that, you have to export this object to GRASS.
Hope this helps,

Clément.

-- 
Clément CALENGE
LBBE - UMR CNRS 5558 - Université 
Claude Bernard Lyon 1 - FRANCE
tel. (+33) 04.72.43.27.57
fax. (+33) 04.72.43.13.88 




More information about the AniMov mailing list