R/convert_gps.R

Defines functions conv_gps

Documented in conv_gps

#' Convert GPS
#'
#' Convert GPS data from WACL van to decimal degrees
#'
#' @param coord latitude or longitude column to be converted
#' 
#' @param direction column containing directional component of coordinates (N, S, E, W)
#' 
#' @author Shona Wilde
#' 
#' @return Numeric of converted coordinate
#' 
#' @export


# function to convert coordinates
conv_gps <- function(coord, direction) 
{
  
  coord <- tryCatch({
    as.numeric(coord)
  }, warning = function(w) {
    coord
  })
  
  is_negative <- ifelse(direction %in% c("S", "W"), TRUE, FALSE)
  int <- floor(coord/100)
  new_coord <- (((coord/100 - int) * 100)/60) + int
  
  
  suppressWarnings(
    
    if (is_negative) 
    new_coord <- ((((coord/100 - int) * 100)/60) + int) * -1
    
  )
  
  return(new_coord)
}
shonawilde/shonarrr documentation built on Jan. 29, 2025, 1:27 a.m.