Return a list of sf_POINTS or a data.frame from a sftraj object

pts_traj(traj, sfc = FALSE)

coord_traj(traj)

Arguments

traj

a trajectory geometery from sf_traj

sfc

TRUE/FALSE should the return by an sfc or a list of points. Defaults to FALSE

Examples

#'
data("raccoon")
raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST")
burstz <- list(id = raccoon$animal_id, month = as.POSIXlt(raccoon$timestamp)$mon)
# Input is a data.frame
my_traj <- as_sftraj(raccoon,
  time = "timestamp",
  error = NA, coords = c("longitude", "latitude"),
  group = burstz
)
print(my_traj, 5, 10)
#> Sftraj with 445 features and 10 fields (168 empty geometries) 
#> Geometry : "geometry" (XY, crs: NA) 
#> Timestamp : "timestamp" (POSIXct in UTC) 
#> Grouping : "sft_group" (*id*, *month*) 
#> -------------------------------
#>   animal_id latitude longitude           timestamp height hdop vdop fix
#> 1   TTP-058       NA        NA 2019-01-19 00:02:30     NA  0.0  0.0  NO
#> 2   TTP-058 26.06945 -80.27906 2019-01-19 01:02:30      7  6.2  3.2  2D
#> 3   TTP-058       NA        NA 2019-01-19 02:02:30     NA  0.0  0.0  NO
#> 4   TTP-058       NA        NA 2019-01-19 03:02:30     NA  0.0  0.0  NO
#> 5   TTP-058 26.06769 -80.27431 2019-01-19 04:02:30    858  5.1  3.2  2D
#>                 sft_group                       geometry
#> 1 (id: TTP-058, month: 0)                    POINT EMPTY
#> 2 (id: TTP-058, month: 0)     POINT (-80.27906 26.06945)
#> 3 (id: TTP-058, month: 0)                    POINT EMPTY
#> 4 (id: TTP-058, month: 0)                    POINT EMPTY
#> 5 (id: TTP-058, month: 0) LINESTRING (-80.27431 26.06...

# extract a list of points
pts_traj(my_traj)[1:10]
#> [[1]]
#> POINT EMPTY
#> 
#> [[2]]
#> POINT (-80.27906 26.06945)
#> 
#> [[3]]
#> POINT EMPTY
#> 
#> [[4]]
#> POINT EMPTY
#> 
#> [[5]]
#> POINT (-80.27431 26.06769)
#> 
#> [[6]]
#> POINT (-80.2793 26.06867)
#> 
#> [[7]]
#> POINT (-80.27908 26.06962)
#> 
#> [[8]]
#> POINT (-80.27902 26.06963)
#> 
#> [[9]]
#> POINT EMPTY
#> 
#> [[10]]
#> POINT (-80.279 26.06982)
#> 

# or a data.frame of points
coord_traj(my_traj)[1:10]
#>  [1]        NA -80.27906        NA        NA -80.27431 -80.27930 -80.27908
#>  [8] -80.27902        NA -80.27900