
Set, create or modify columns with sf
spatial information
Source: R/set_coordinates_sf.R
set_coordinates_sf.Rd
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 POINT
as 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.
Arguments
- .df
A
data.frame
ortibble
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.
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()
#> ⠙ Checking 1 column: geometry
#> ✔ Checking 1 column: geometry [310ms]
#>
#> • Converted geometry → decimalLongitude, decimalLatitude, and geodeticDatum.
#> Warning: geometry dropped from data frame.
#> # A tibble: 3 × 5
#> scientificName eventDate decimalLongitude decimalLatitude geodeticDatum
#> * <chr> <chr> <dbl> <dbl> <chr>
#> 1 Crinia Signifera 2010-10-14 149. -35.3 EPSG:4326
#> 2 Crinia Signifera 2010-10-14 149. -35.2 EPSG:4326
#> 3 Litoria peronii 2010-10-14 149. -35.8 EPSG:4326