% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get_geometry.R
\name{get_geometry}
\alias{get_geometry}
\title{Get geometry}
\usage{
get_geometry(
  DT = NULL,
  coords = NULL,
  crs = NULL,
  output_crs = NULL,
  geometry_colname = "geometry"
)
}
\arguments{
\item{DT}{input data.table}

\item{coords}{character vector of X coordinate and Y coordinate column names.
Note: the order is assumed X followed by Y column names}

\item{crs}{numeric or character defining the coordinate reference system to
be passed to \link[sf:st_crs]{sf::st_crs}. For example, \code{crs = "EPSG:32736"} or
\code{crs = 32736}.}

\item{output_crs}{default NULL, the output crs to transform the input
coordinates to with \link[sf:st_transform]{sf::st_transform}. If output_crs is NULL or
matching the crs argument, the coordinates will not be transformed}

\item{geometry_colname}{default "geometry", to optionally set output name
of simple feature geometry list column}
}
\value{
\code{get_geometry} returns the input \code{DT} appended with a
\code{geometry} column which represents the input coordinates
as a \code{sfc} (simple feature geometry list column). If the \code{output_crs}
was provided, the \code{geometry} will be transformed to the \code{output_crs}.

A message is returned when a column named \code{geometry} already exists in
the input \code{DT}, because it will be overwritten.

See details for appending outputs using modify-by-reference in the
\href{https://docs.ropensci.org/spatsoc/articles/faq.html}{FAQ}.
}
\description{
\code{get_geometry} sets up an input \code{DT} with a 'geometry' column for spatsoc's
geometry interface. The function expects a \code{data.table} with relocation data and
a coordinate reference system.
}
\details{
The \code{DT} must be a \code{data.table}. If your data is a \code{data.frame}, you can
convert it by reference using \code{\link[data.table:setDT]{data.table::setDT()}} or by reassigning using
\code{\link[data.table:data.table]{data.table::data.table()}}.

The \code{coords} argument expects the names of columns in \code{DT} which correspond
to the X and Y coordinates.

The \code{output_crs} argument allows the user to set an output \code{crs} for their
geometry column. Note: some functions in spatsoc (eg. those that measure
directions like \code{edge_direction} and \code{direction_to_leader}) require
geographic coordinates and it is therefore simpler to leave the default
\code{output_crs = 4326}.
}
\examples{
# Load data.table
library(data.table)
\dontshow{data.table::setDTthreads(1)}

# Read example data
DT <- fread(system.file('extdata', 'DT.csv', package = 'spatsoc'))

# Get geometry
get_geometry(DT, coords = c('X', 'Y'), crs = 32736)

# Print
print(DT)
}
