Thank you, I have just installed this package but it will still not work. I tried geo.buffer however it said I have projected coordinates (UTM) not lat long. You will see object 'Range' has been given the gBuffer argument. It was working correctly until yesterday. Thanks you for helping ![:slight_smile: :slight_smile:](https://forum.posit.co/images/emoji/apple/slight_smile.png?v=12)
This is the function my teacher created to make the detection series and apply the buffer of 300m::
detection_series<-function(animaltrack, receiver.locs, mydirectory, easting, northing) {
packages<-function(x){
x<-as.character(match.call()[[2]])
if (!require(x,character.only=TRUE)){
install.packages(pkgs=x,repos="http://cran.r-project.org")
require(x,character.only=TRUE)
}
}
packages(rgdal)
packages(spatialEco)
packages(RColorBrewer)
library(rgdal)
rec.sp<-SpatialPointsDataFrame(coords=matrix(c(receiver.locs$x, receiver.locs$y), nrow=nrow(receiver.locs), ncol=2), data=as.data.frame(receiver.locs$id), proj=CRS('+proj=utm +zone=55 +south +ellps=GRS80 +units=m +no_defs'))
range<-gBuffer(rec.sp, byid=T, id=rec.sp[[1]], width=300)
track.sp<-SpatialPointsDataFrame(coords=matrix(c(animaltrack$x, animaltrack$y), nrow=nrow(animaltrack), ncol=2), data=as.data.frame(animaltrack$date), proj=CRS('+proj=utm +zone=55 +south +ellps=GRS80 +units=m +no_defs'))
track.line<-Lines(list(Line(coordinates(track.sp))), 'animal')
dets<-point.in.poly(track.sp, range)
det<-data.frame(date=dets[[1]], rec.id=dets[[2]])
det$x<-receiver.locs$x[match(det$rec.id, receiver.locs$id)]
det$y<-receiver.locs$y[match(det$rec.id, receiver.locs$id)]
land<- readOGR(dsn=mydirectory, layer="tas_land_map_wgs84")
land.utm<-spTransform(land, CRS('+proj=utm +zone=55 +south +ellps=GRS80 +units=m +no_defs'))
mpas<- readOGR(dsn=mydirectory, layer="maria_reserve")
if(.Platform$OS.type=="windows") {
quartz<-function() windows()
}
quartz()
plot(land.utm, xlim=easting, ylim=northing, col='lightgrey',xlab='Easting (UTM)', ylab='Northing (UTM)', axes=TRUE, xaxs='i', yaxs='i')
plot(mpas, add=T, col=adjustcolor('indianred1', .5))
plot(rec.sp, add=T, pch=20)
plot(range, add=T)
lines(animaltrack$x, animaltrack$y, col='red')
return(det)
}