Skip to contents

This function calculates time since sunrise, time since sunset, and day and night hours for points in an sf object. The function also optionally saves the output as an RDS file.

Usage

get_daynight_times(
  points,
  time_column_name = NULL,
  save = FALSE,
  savepath = "./output/extracted_day_night_stats.rds",
  units = "hours"
)

Arguments

points

An sf object containing geometry and a time_column with datetime as a lubridate::interval.

time_column_name

Name of the time column in the dataset. If NULL (the default), a column of type lubridate::interval is automatically selected.

save

A logical value indicating whether to save the extracted day and night time information as an RDS file. Default is FALSE.

savepath

The path to save the RDS file, defaults to './output/extracted_day_night_stats.rds'.

units

A string specifying the units of time to return, defaults to 'hours'.

Value

An sf object containing the original points and additional day and night time-related information.

Examples

if (FALSE) { # \dontrun{
sf_with_times <- get_daynight_times(
  points_sf,
  save=TRUE,
  savepath='./daynight.rds', units='minutes'
)
} # }