[AniMov] Clipping area from home range estimate

Tim Clark mudiver1200 at yahoo.com
Mon Oct 5 22:01:31 CEST 2009

Dear Adehabitat Gurus,

I am bringing up a subject I posed a few months ago because it keeps creating problems for me.  


I work on fish that swim into little bays and around points of land, and my home range calculations always include land area as part of the home range.  I have been using qGIS to remove the land area, but I am now trying to look at changes in home range size as sample size increases.  Easy to do normally, but not when I have to manually clip the land out.  I came up with an easy way to do it using setdiff() from the gpclib package.  I have detailed shapefiles of the land which I convert to gpc polygons, then use setdiff() to remove the land from the gpc polygons created by the home range fuctions.  While this works, I am trying to write a more general function that will replace the date from the original home range object with the clipped data so that it is compatible with other functions in Adehabitat.  I am currently working on the NNCH home range function since that is what I am using on my current project.  I am having a problem replacing the area in
 the NNCH object with the new area for the home range isopleths.  I think this is simply due to my lack of understanding of how lists work, and would appreciate your help.  The problem line that I think is needed is commented out(homerange[[kk]]$area[[i,]]<-area).  Below is the function and example data.  I have used the chamois dataset and created a gpc polygon called "BigLake" to represent an uninhabitable area for goats.

Thanks for your help and suggestions,


#Input NNCH homerange, a GPC Polygon of area to cut, and other stuff
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, id = id, k = k, a = a, r = r)
    for (kk in names(homerange)) {
        polys <- homerange[[kk]]$polygons

        for (i in 1:length(percent)) {
            isoIndex <- NNCH.iso.index(homerange[[kk]], percent[i])
            if (is.integer(isoIndex)) {



#Example data
xy <- chamois$locs
hr <- NNCH(xy, k = c(12,14))

BigLake <- cbind(c(865000,870000,870000,865000),c(2045000,2045000,2050000,2050000))
BigLake <- as(BigLake[chull(BigLake), ], "gpc.poly")

#Run function

Tim Clark
Department of Zoology 
University of Hawaii


More information about the AniMov mailing list