Using adehabitat and splancs to achieve point-in-polygon analysis on raster?
Hi Clement, Hope you had a good time in the field! Is it spring in France? Thanks for the very helpful reply! I will try it right now! I need to present at a conference in early April and would like to get these results before that! Just three quick questions before you go to enjoy the Easter weekend: - how do I get the values out of 'jj' (## jj contains the values of elevation inside the home range of the animals) to calculate mean, variance, etc, across all the points in 'jj'? I assume 'jj' is of class 'kasc'. In my case it might be 'asc' as I will have only a single home range at the time (one animal). - can I get the points out of the 'kasc' object in a way that I can still run spatial statistics on them? I would like to calculate the nugget and range for the NDVI values within the home range. - do you know how to convert a polygon shapefile into the same class as produced by the command kernelUD? Alternatively I could import a raster version of the polygon shape file, convert it to the correct format, and repeat the spatial join method you are suggesting for the home ranges! Thanks again, Sander.
Cl?ment Calenge wrote:
Dear Sander, Sorry for my late answer, I was in the field.
I send this email to you directly, because it concerns the link between Adehabitat and Splancs. I have two sources of polygons: - polygon shape files with areas of interest; - polygons calculated using the home range methods in Adehabitat. For the moment, each polygon source will only contain a single polygon. I have one source of points: a grid representing NDVI values. I read the grid using the import.asc function in Adehabitat. I would like to use both polygon sources to select the points in the NDVI raster which are inside the relevant polygons. Then I want to run several statistics (mean, standard deviation, etc) on the NDVI values of these points.
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.
-------------------------------------------- Dr. Sander P. Oom Animal, Plant and Environmental Sciences, University of the Witwatersrand Private Bag 3, Wits 2050, South Africa Tel (work) +27 (0)11 717 64 04 Tel (home) +27 (0)18 297 44 51 Fax +27 (0)18 299 24 64 Email sander at oomvanlieshout.net Web www.oomvanlieshout.net/sander