% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cleanDepth.R
\name{cleanDepth}
\alias{cleanDepth}
\title{Clean and flag coordinates based on intersection with a land polygon,
intersection with a bathymetry layer, and/or by a given depth range}
\usage{
cleanDepth(
  occs,
  bathy,
  land_poly,
  depth_range,
  flag = FALSE,
  bottom_correct = FALSE
)
}
\arguments{
\item{occs}{dataframe containing columns named "longitude", "latitude", and "depth," where
depth values are positive}

\item{bathy}{a spatRaster of bathymetry in the same units as the occurrence depth, where
values are negative}

\item{land_poly}{optional polygon of continents in same projection as occurrence data}

\item{depth_range}{optional range of depth values in the form of c(upper, lower) in which
all points should fall between. depth value should be positive, as in the case of the occs}

\item{flag}{default is F, if T, points are not removed, but flagged if they intersect, and a
column is added to the output indicating what points have been flagged}

\item{bottom_correct}{default is F, but if T, points are not removed, and a column is added
to the output displaying the bathymetry value at the flagged point for corrective purposes}
}
\value{
an object of class dataframe containing cleaned or flagged occurrences
}
\description{
function to remove or flag coordinates on land, coordinates which are deeper
than the known bathymetry at a given xy location, and/or coordinates outside of
a specified depth range when cleaning coordinates for species in marine environments
}
\details{
assumes depths are listed as positive in the occs and depth_range, while the
bathymetry layer lists them as negative when below the sea surface
}
\examples{
library(terra)
library(dplyr)

# Create sample bathymetry
r1 <- rast(ncol=10, nrow=10)
values(r1) <- c(-100:0)

# Create test occurrences
set.seed(0)
longitude <- sample(ext(r1)[1]:ext(r1)[2], size = 10, replace = FALSE)
set.seed(0)
latitude <- sample(ext(r1)[3]:ext(r1)[4], size = 10, replace = FALSE)
set.seed(0)
depth <- sample(1:100, size = 10, replace = TRUE)
occs <- data.frame(longitude, latitude, depth)

#Heres the function
result <- cleanDepth(bathy = r1, occs = occs)

}
\keyword{cleaning}
\keyword{occurrence}
