locs2sf: Convert matrix or data frame with point coordinates to a...

View source: R/locs2sf.R

locs2sfR Documentation

Convert matrix or data frame with point coordinates to a spatial (sf) object

Description

Convert matrix or data frame with point coordinates to a spatial (sf) object

Usage

locs2sf(locs, crs = 4326, lon.col = NULL, lat.col = NULL)

Arguments

locs

A matrix or data frame containing point coordinates data. If a matrix, the first two columns will be assumed to contain longitude and latitude coordinates, respectively. If a data frame, the function will try to guess the columns containing the coordinates based on column names, unless lon.col and lat.col are provided.

crs

A character string, number (EPSG value), or crs object specifying the coordinate reference system (see sf::st_crs() or https://spatialreference.org). Default is geographic (unprojected) coordinates, datum WGS84 (EPSG = 4326).

lon.col

Character (optional). Name of the column containing longitude data.

lat.col

Character (optional). Name of the column containing latitude data.

Value

An sf::sf() object.

Examples

locs <- matrix(runif(20), ncol = 2)
locs2sf(locs)

locs <- data.frame(species = rep("Laurus nobilis", 10), x = runif(10), y = runif(10))
locs2sf(locs)

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