Hello,
I have several annual lists of telemetry objects for multiple individuals from different locations. My problem is that most of these individuals were tracked in UTM zone 12, but a few were located in UTM zone 11, and several of my annual datasets contain individuals from both UTM zones. This has resulted in the home range polygons and coordinates of the zone 11 individuals being shifted far to the right when I export the data to google earth for visualization. Is there any way to assign different projections to individuals within the same list of telemetry objects? Here's an example of my work so far using the buffalo data. In this example I'm assuming that the buffalo Toni was tracked in UTM zone 11, while all others were tracked in UTM zone 12. I'm not sure if the place to assign the utm zone 11 projection to Toni would be at lines 75-76 where the telemetry objects are assigned to a projection, or at line 92 where the CRS for the spatial points dataframes is defined. I'm also not quite sure how I would go about assigning a diffreent projection to just Toni. Is there any way to specifically assign Toni to the UTM zone 11 projection? Thanks!
Jason
#adding libraries
library(ctmm)
library(ggplot2)
library(dplyr)
library(stringr)
library(lubridate)
library(sf)
library(tidyverse)
library(sp)
library(scales)
library(tidyr)
library(tibble)
#Load the data
data("buffalo")
#Creating individual dataframes and adding an id column
Cilla <- as.data.frame(buffalo$Cilla)
Cilla$id<-"Cilla"
Gabs<-as.data.frame(buffalo$Gabs)
Gabs$id<-"Gabs"
Mvubu<-as.data.frame(buffalo$Mvubu)
Mvubu$id<-"Mvubu"
Pepper<-as.data.frame(buffalo$Pepper)
Pepper$id<-"Pepper"
Queen<-as.data.frame(buffalo$Queen)
Queen$id<-"Queen"
Toni<-as.data.frame(buffalo$Toni)
Toni$id<-"Toni"
#Combining dataframes
buffalo.df <- rbind(Cilla,Gabs,Mvubu,Pepper,Queen,Toni)
#adding a year column
buffalo.df$Year<-year(buffalo.df$timestamp)
buffalo.df$Year<-as.factor(buffalo.df$Year)
#adding a utm zone column
buffalo.df$UTM.zone<-"12 +datum=NAD27"
#changing the utm zone of Toni to zone 11
buffalo.df$UTM.zone[which(buffalo.df$id == "Toni")] = "11 +datum=NAD27"
#duplicating the timestamp to split into date and time
buffalo.df$timestamp <- ymd_hms(buffalo.df$timestamp)
buffalo.df$Timestamp<-buffalo.df$timestamp
#Splitting the extra timestamp into a date and time column
buffalo.df <- separate(buffalo.df, timestamp, c("date","time"), sep= " ", remove= TRUE, extra= "merge")
#Reordering columns
buffalo.df <- buffalo.df[, c(8,9,1,2,6,7,11,10)]
#Splitting data by year
data2005<-buffalo.df %>%
filter(Year==2005)
data2006<-buffalo.df %>%
filter(Year==2006)
#Creating annual telemetry data
Tdata2005<-as.telemetry(data2005, timeformat="auto",timezone="UTC",
timeout=Inf,datum="NAD27",
na.rm="row",mark.rm=FALSE,keep=FALSE,drop=FALSE)
Tdata2006<-as.telemetry(data2006, timeformat="auto",timezone="UTC",
timeout=Inf,datum="NAD27",
na.rm="row",mark.rm=FALSE,keep=FALSE,drop=FALSE)
#Assigning projections to telemetry objects
projection(Tdata2005)<- "+proj=utm +zone=12 +datum=NAD27 +units=m +no_defs"
projection(Tdata2006)<- "+proj=utm +zone=12 +datum=NAD27 +units=m +no_defs"
#Create a list of both telemetry objects
Tdata<-list(Tdata2005,Tdata2006)
names(Tdata)<-c("Tdata2005","Tdata2006")
#Create a list of years
Years<-c("2005","2006")
#Writing spatial points dataframes for point data
points2shape <- function(x, date) {
xy<-list()
points<-list()
for (i in 1:length(x)) {
xy <- x[[i]][c(5,6)]
points[[i]] <- SpatialPointsDataFrame(coords = xy, data = x[[i]],
proj4string = CRS("+proj=utm +zone=12 +datum=NAD27 +units=m +no_defs"))}
return(points)
}
#applying the spatial points dataframe function to the list of data
points_list<-lapply(seq_along(Tdata), function(i) points2shape(Tdata[[i]], Years[i]))
# adding names
for (i in 1:length(points_list)) {
names(points_list)<-names(Tdata)
names(points_list[[i]])<-names(Tdata[[i]])
}
#Create a function to write shapefiles based on the spatial dataframes
writeshape <- function(x, date) {
xy<-list()
points<-list()
for (i in 1:length(x)) {
raster::shapefile(x[[i]],filename=paste(names(x[i]), "(", date, ")", ".jpg", sep = "", overwrite=TRUE))
}
}
#applying the function to write shapefiles
lapply(seq_along(points_list), function(i) writeshape(points_list[[i]], Years[i]))