Hi - I'm trying to write a simulation that loops over an animal movement
track, creates a buffer at each x,y,t, and samples an underlying grid (sort
of like Zonal Stats in ArcInfo).

To create the polygon buffer centered on the current position and with
radius r, I've written:

poly <- function(x,y,r){
    phi <- seq(0,2*pi,length.out=30)
    xy <- matrix(NA, nrow=length(phi),ncol=2)
        for(i in 1:length(phi)){
            xy[i,1] <- x + (r * cos(phi[i]))
            xy[i,2] <- y + (r * sin(phi[i]))
        }
    xy[i,1:2] <- xy[1,1:2]
    xysp <- Polygon(xy,hole=F)
    return(xysp)
}

Then calling it:

test <- poly(xy[t,1], xy[t,2], 2)

But when I try overlay(df,test), I get

> overlay(df,test, fn=mean)
Error in function (classes, fdef, mtable)  :
        unable to find an inherited method for function "overlay", for
signature "SpatialGridDataFrame", "Polygon"

> class(df)
[1] "SpatialGridDataFrame"
attr(,"package")
[1] "sp"

> class(test)
[1] "Polygon"
attr(,"package")
[1] "sp"

I thought the error might be in the way I am calling df within overlay, but
it's not clear from overlay-methods if this even possible. To test this, I
tried

overlay(as(df,"SpatialPoints"),test)
Error in function (classes, fdef, mtable)  :
        unable to find an inherited method for function "overlay", for
signature "SpatialPoints", "Polygon"

I also thought it might be a problem with using Polygon, instead of
SpatialPolygons, but seems like I can't use the latter with a single
polygon. Am I missing something easy?

Thanks,
Rob

-- 
Rob Schick
Ph.D. Candidate, Ecology
Duke University
Durham, NC 27708
http://www.duke.edu/~rss10/ <http://www.duke.edu/%7Erss10/>
Lab: 919-613-8021, Ext. 3

	[[alternative HTML version deleted]]


