Skip to content
Prev 355 / 29559 Next

Using adehabitat and splancs to achieve point-in-polygon analysis on raster?

Dear Sander,

Sorry for my late answer, I was in the field.
The solution depends on what you call "polygon". The function mcp.rast() 
is intended to "rasterize"
a polygon on a raster grid of class "asc" or "kasc". The polygon is here 
stored as a data frame with
two columns (the X and Y coordinates of the polygon). The function 
hr.rast() can be used if you have
an object of class "area", i.e. a data.frame with three columns (the X 
and Y coordinates of the polygon,
and a third column defining the ID of the polygon).

Now, it seems that  you work with more complex type of polygons, e.g. 
kernel estimations of home ranges
(where each animal has an home range, and each home range can be made of 
several polygons). In such cases,
the "Spatial join" operation can be more complex. I detail below an 
example of "spatial join" with a kernel
estimation of wild boar home ranges. Note, that in this case, you do not 
have to compute the contour of
the estimation. Just copy and paste the lines below on R:

## loads and display the data
library(adehabitat)
data(puechabon)

## keep only the elevation
el<-getkasc(puechabon$kasc,1)
image(el)

## estimate a kernel home-range
 kud<-kernelUD(puechabon$locs[,c("X","Y")], puechabon$locs$Name, grid=el)
## kud contains a density
## note that the grid containing the values of the elevation is used for 
the estimation

vud<-getvolumeUD(kud)
image(vud)
## vud contains the limits of the home ranges estimated at different levels

toto<-lapply(vud, function(x) x$UD)
## toto is the list of maps of Utilization Distribution
tutu<-lapply(toto, function(x) {x[x<95]<-1; x[x>95]<-NA; return(x)})
## tutu is a list of raster maps containing 1 if the pixel is inside
## the 95% home range and NA otherwise

foo<-as.kasc(tutu)
image(foo)
## foo is a kasc object

jj=lapply(foo, function(x) x*el)
image(jj)
## jj contains the values of elevation inside the home range of the animals

The last method that is available for home-range estimation of animals 
home ranges
is the Nearest Neighbor Convex hull method of Getz and Wilmers (2004). 
The function
NNCH.rast() can be used to "rasterize" the home range estimation in the 
same way, and then
you can multiply the resulting maps with your NDVI in the same way.
Hope this helps,


Cl?ment.