[R-sig-Geo] Re: Using adehabitat and splancs to achieve point-in-polygon analysis on raster?
Clément Calenge
calenge at biomserv.univ-lyon1.fr
Fri Mar 25 15:35:29 CET 2005
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.
--
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 R-sig-Geo
mailing list