Reply-to:[email protected]
Dear Adehabitat List,
After getting a little help I was able to answer my own question. The home
range estimate for some reason gives a whole range of "levels" for each
polygon/area. I still don't understand why, but there are multiple 100 percent
isopleth levels in the homerange. Indexing by these levels allowed me to
compute new gpc polygons and recalculate the area for the polygon.
The working function and example data are below.
Aloha,
Tim
cut.NNCH<-function (x=hr, GPC.poly=BigMountain, percent = rev(seq(10,100, by =
10)), id = NULL, k = NULL, r = NULL, a = NULL, ...)
{
if (!inherits(x, "NNCH"))
stop("x should be of class \"NNCH\"")
if (!require(sp))
stop("package sp required")
if (!require(gpclib))
stop("package gpclib required")
e <- NULL
percent <- rev(vectorize.parameter(percent))
homerange <- NNCH.select(x, k = k, a = a, r = r)
for (kk in names(homerange)) { #Index of
number of k,r, or a values
polys <- homerange[[kk]]$polygons
level <- length(homerange[[kk]]$polygons)
for (i in 1:level) { #Index of number
of percent values
NNCH.poly<-polys[[i]] #gpc polygon of
indexed home range
cut.poly<-setdiff(NNCH.poly,GPC.poly) #Cuts
land from homerange
homerange[[kk]]$polygons[[i]]<-cut.poly #Replaces
homerange with cut homerange in class "gpc.poly"
ar<-area.poly(homerange[[kk]]$polygons[[i]]) #Calculate area
of gpc polygon #Create data frame of isopleth levels and area
homerange[[kk]]$area[[i,2]]<-ar
}
}
return(homerange)
}
#Example data
library(adehabitat)
data(chamois)
xy <- chamois$locs
hr <- NNCH(xy, k = c(12,14))
plot(hr)
BigLake <-
cbind(c(865000,870000,870000,865000),c(2045000,2045000,2050000,2050000))
BigLake <- as(BigLake[chull(BigLake), ], "gpc.poly")
plot(BigLake,add=TRUE)
#Run function
new.range<-cut.NNCH(x=hr,GPC.poly=BigLake)
plot(new.range)
Tim Clark
Department of Zoology
University of Hawaii
_______________________________________________
AniMov mailing list
[email protected]
http://lists.faunalia.it/cgi-bin/mailman/listinfo/animov