point_over_poly_DT: Check if points are over a polygon (e.g. study site)

View source: R/point_over_poly_DT.R

point_over_poly_DTR Documentation

Check if points are over a polygon (e.g. study site)

Description

Check if points are over a polygon (e.g. study site)

Usage

point_over_poly_DT(
  DT,
  lat = "lat",
  lon = "lon",
  poly,
  buffer = NA,
  projection = paste0("+proj=laea +lat_0=90 +lon_0=-156.653428 +x_0=0 +y_0=0",
    " +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 ")
)

Arguments

DT

Name of the data.table

lat

Name of the column with latitude (as.character)

lon

Name of the column with longitude (as.character)

poly

Name of the polygon to overlap the data with (changes projection to PROJ)

buffer

Buffer distance (see st_buffer)

projection

Projection of the data (default is equal area with centre Barrow)

Value

Data.table with additional conditional column poly_overlap

Examples

require(data.table)

# load study site
study_site

# create table with one inside and one outside the study site
DT = data.table(name = c('NARL', 'Utqiagvik', 'BARC'),
                lat  = c(71.320854, 71.290246, 71.324966),
                lon  = c(-156.648210, -156.788622, -156.667220))

# change projection
st_transform_DT(DT)
point_over_poly_DT(DT, lat = 'lat', lon = 'lon', poly = study_site)

## Not run: 
# check data
require(ggplot2)
ggplot() +
  geom_sf(data = study_site, fill = 'grey95') +
  geom_point(data = DT, aes(lon, lat, color = poly_overlap))

## End(Not run)

krietsch/auksRuak documentation built on Feb. 15, 2023, 2:44 p.m.