set_coordinates_sf: Set, create or modify columns with 'sf' spatial information

View source: R/set_coordinates_sf.R

set_coordinates_sfR Documentation

Set, create or modify columns with sf spatial information

Description

This function helps format standard location fields like longitude and latitude point coordinates to a tibble using Darwin Core Standard.

It differs from set_coordinates() by accepting sf geometry columns of class POINTas coordinates (rather than numeric lat/lon coordinates). The advantage of using an sf geometry is that the Coordinate Reference System (CRS) is automatically formatted into the required geodeticDatum column.

Usage

set_coordinates_sf(.df, geometry = NULL, .keep = "unused")

Arguments

.df

A data.frame or tibble that the column should be appended to.

geometry

The latitude/longitude coordinates as sf POINT class

.keep

Control which columns from .data are retained in the output. Note that unlike dplyr::mutate(), which defaults to "all" this defaults to "unused"; i.e. only keeps Darwin Core columns, and not those columns used to generate them.

Value

A tibble with the requested columns added/reformatted.

See Also

set_coordinates() for providing numeric coordinates, set_locality() for providing text-based spatial information.

Examples

df <- tibble::tibble(
  scientificName = c("Crinia Signifera", "Crinia Signifera", "Litoria peronii"),
  latitude = c(-35.27, -35.24, -35.83),
  longitude = c(149.33, 149.34, 149.34),
  eventDate = c("2010-10-14", "2010-10-14", "2010-10-14")
  ) |>
  sf::st_as_sf(coords = c("longitude", "latitude")) |>
  sf::st_set_crs(4326)

# Reformat columns to Darwin Core Standard terms.
# Coordinates and CRS are automatically detected and reformatted.
df |>
  set_coordinates_sf()



corella documentation built on April 4, 2025, 12:20 a.m.