as_sf: Put results back on the geometries of a spatial frame

View source: R/frames.R

as_sfR Documentation

Put results back on the geometries of a spatial frame

Description

Joins a sample, a frontier allocation or any data frame with a unit column to the geometries of the sf object the frame came from, for maps.

Usage

as_sf(x, sf, unit = NULL)

Arguments

x

A data frame with a unit column (a fieldopt_sample, for example).

sf

The sf object that as_frame() was applied to.

unit

Name of the column with the unit names in sf, as in as_frame().

Value

An sf object with the columns of x.

Examples

if (requireNamespace("sf", quietly = TRUE)) {
  sq <- sf::st_sfc(sf::st_polygon(list(rbind(c(0, 0), c(0, 1), c(1, 1), c(1, 0), c(0, 0)))),
    crs = 4326
  )
  cells <- sf::st_sf(geometry = sf::st_make_grid(sq, n = 4))
  s <- select_units(as_frame(cells), n = 4, seed = 1)
  as_sf(s, cells)
}

fieldopt documentation built on Oct. 22, 2026, 1:07 a.m.