point_in_cell: Check if points (occurrences) fall within raster cells with...

View source: R/point_in_cell.R

point_in_cellR Documentation

Check if points (occurrences) fall within raster cells with data

Description

This function examines which points fall within a raster cell with data (not NA). Returns TRUE for points falling in a raster cell with data, and FALSE otherwise.

Usage

point_in_cell(locs = NULL, ras = NULL, layer = 1)

Arguments

locs

An sf::sf() or terra::SpatVector() object with point coordinates, e.g. as generated from locs2sf() or locs2vect().

ras

terra::SpatRaster() object

layer

Integer. Raster layer to use for comparing with point locations (default = 1).

Value

A logical vector.

Examples

locs <- data.frame(lon = c(1, 2, 1, 2), lat = c(1, 1, 2, 3))
locs.sf <- locs2sf(locs)
library(terra)
ras <- rast(nrows = 2, ncols = 2, xmin = 0.5, xmax = 3.5, ymin = 0.5, ymax = 3.5,
 resolution = 1, vals = c(NA, 1, 1, NA, NA, 1, NA, 1, 1))
occmap(locs.sf, ras, pcol = "black", psize = 3)

point_in_cell(locs.sf, ras)

# adding column to original point data
locs.sf$inras <- point_in_cell(locs.sf, ras)
locs.sf


Pakillo/rSDM documentation built on March 1, 2025, 12:30 a.m.