I am having trouble setting the crs with the crs argument within the make_track function. It consistently just returns crs as NA with no error. I am not sure if there is conflicting packages or if I am missing something.
library(knitr)
library(sf)
library(lubridate)
library(terra)
library(amt)
library(tibble)
library(dplyr)
# Load data from working directory, previously unzipped and downloaded from
# https://alaska.usgs.gov/data1/polarBear/polarBear_onLand_westHudsonBay_pagano/polarBear_GPSLocation_westHudsonBay_2019-2022.zip
polarBear_GPS <- read.csv("/Users/elleryvincent/Desktop/Spatial Ecology/polarBear_GPSLocation_westHudsonBay_2019-2022/polarBear_GPSLocation_westHudsonBay_2019-2022.csv")
# Check for NA values, 0 == no NA values in df
sum(is.na(polarBear_GPS))
# [1] 0
### Skip following if previous step returns 0
# ind <- complete.cases(polarBear_GPS[, c("Datetime", "Longitude", "Latitude")])
#
# polarBear_GPS <- polarBear_GPS[ind == TRUE, ]
#
# # Remove NA values from Datetime
# polarBear_GPS <- polarBear_GPS[!is.na(polarBear_GPS$Datetime), ]
###
# Make Datetime a date/time variable
polarBear_GPS$Datetime <- as.POSIXct(polarBear_GPS$Datetime, format="%m/%d/%Y %H:%M:%S", tz = "UTC")
# Check for duplicated timestamps per bear
polarBear_GPS |>
summarise(ts_dupes = any(duplicated(Datetime)), .by = Bear)
# If any return true, run following step, else skip
polarBear_GPS <- polarBear_GPS |>
distinct(Datetime, .keep_all = TRUE, .by = Bear)
st_crs(polarBear_GPS, 4326)
# Create the track with correct CRS (see metadata at download link above)
trk1 <- make_track(
polarBear_GPS,
.x = Longitude,
.y = Latitude,
.t = Datetime,
id = Bear,
crs = 4326)
`
This is the sf version
Linking to GEOS 3.12.2, GDAL 3.9.2, PROJ 9.4.1; sf_use_s2() is
` head(trk1)
# A tibble: 6 × 4
x_ y_ t_ id
* <dbl> <dbl> <dttm> <chr>
1 -93.2 58.8 2019-08-26 20:20:11 X17517
2 -93.2 58.8 2019-08-26 20:25:10 X17517
3 -93.2 58.8 2019-08-26 20:30:09 X17517
4 -93.2 58.8 2019-08-26 20:35:09 X17517
5 -93.2 58.8 2019-08-26 20:40:09 X17517
6 -93.2 58.8 2019-08-26 20:45:09 X17517`
I am having trouble setting the crs with the crs argument within the make_track function. It consistently just returns crs as NA with no error. I am not sure if there is conflicting packages or if I am missing something.
I am also certain this data is WGS84
Thank you for the help