Skip to content

Commit

Permalink
testy - resolves #63
Browse files Browse the repository at this point in the history
  • Loading branch information
dhduncan committed Oct 30, 2024
1 parent 5a60afe commit 82a9e84
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions R/assign_nearest_land.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#' @title Assign to nearest raster cell on mask
#' @description
#' Adapted from seegSDM.
#' Reposition observations to a location within mask if within a specified distance.
#' Reposition point observations to a location within mask if within a specified distance.
#' Useful for when coastal observations drop off jagged mask and similar
#'
#' @param dat_object data.frame
Expand All @@ -19,15 +19,21 @@ assign_nearest_land <- function(dat_object,
max_distance,
verbose=TRUE) {

stopifnot(sum(colnames(dat_object) %in% c("longitude", "latitude"))==2)
message("dat_object object must contain columns 'longitude' and 'latitude'.")
if(!sum(colnames(dat_object) %in% c("longitude", "latitude"))==2) {

# ensure that data object is spatial data frame
spat_dat <- sf::st_as_sf(dat_object)
stop("Error: dat_object object must contain columns 'longitude' and 'latitude'.")

}

# ensure that data object is a simple features spatial data frame
spat_dat <- sf::st_as_sf(dat_object, coords = c("longitude", "latitude"))

# assert that mask is SpatRaster
stopifnot(inherits(mask_object, 'SpatRaster'))
message("mask must be a SpatRaster")
if(!inherits(mask_object, 'SpatRaster')) {

stop("Error: mask must be a SpatRaster")

}

# isolate coord info from spatial data frame
data_coords <- sf::st_coordinates(spat_dat)
Expand Down

0 comments on commit 82a9e84

Please sign in to comment.