% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/internal.R
\name{calc_direction}
\alias{calc_direction}
\title{Calculate direction}
\usage{
calc_direction(geometry_a, geometry_b, x_a, y_a, x_b, y_b, crs, use_transform)
}
\arguments{
\item{geometry_a, geometry_b}{sfc (simple feature geometry list column) from
\code{\link[=get_geometry]{get_geometry()}}}

\item{x_a, x_b}{X coordinate column, numeric}

\item{y_a, y_b}{Y coordinate column, numeric}

\item{crs}{crs for x_a, y_a (and if provided, x_b, y_b) coordinates,
ignored for geometry_a and geometry_b arguments}

\item{use_transform}{boolean predetermine if coordinates/geometry need transform}
}
\value{
Direction in units of radians, in range of pi, -pi where North = 0.
}
\description{
\strong{Internal function} - not developed to be used outside of spatsoc functions
}
\details{
Calculate direction using \code{\link[lwgeom:st_geod_azimuth]{lwgeom::st_geod_azimuth()}} between one of:
\itemize{
\item the sequence of points in geometry_a
\item the sequence of points in x_a, y_a
\item the pairwise points in geometry_a and geometry_b
\item the pairwise points in x_a, y_a and x_b, y_b
}

Requirements:
\itemize{
\item matching length between a and b objects if b provided
\item crs is provided. If crs is not longlat (as determined by
\code{\link[sf:st_is_longlat]{sf::st_is_longlat()}}), the coordinates or geometry will be transformed to
\code{sf::st_crs(4326)}
\item no missing values in coordinates
}
}
\examples{
# Load data.table
library(data.table)
\dontshow{data.table::setDTthreads(1)}

# Example result for East, North, West, South directions
example <- data.table(
  X = c(0, 5, 5, 0, 0),
  Y = c(0, 0, 5, 5, 0)
)
# E, N, W, S
example[, spatsoc:::calc_direction(x_a = X, y_a = Y, crs = 4326, use_transform = FALSE)]
}
\keyword{internal}
