Skip to contents

locs_from_sf() converts sf point features into the data frame shape expected by popmaps(), tune_popmaps(), and compare_popmaps_surfaces(). The returned table has site, longitude, latitude, and ancestry coefficient columns.

Usage

locs_from_sf(
  x,
  ancestry_cols = NULL,
  site_col = NULL,
  crs = "EPSG:4326",
  coord_names = c("lon", "lat")
)

Arguments

x

An sf object with point geometries.

ancestry_cols

Ancestry coefficient columns, supplied as names or integer positions. If NULL, all numeric non-geometry columns except site_col are used.

site_col

Optional site identifier column, supplied as a name or integer position. If NULL, a column named site, sample, id, name, or population is used when present; otherwise synthetic site names are created.

crs

CRS to transform the coordinates to before extracting x/y values. The default is "EPSG:4326" for longitude/latitude output. Set crs = NULL to keep the input CRS.

coord_names

Names for the returned coordinate columns.

Value

A data frame accepted by POPMAPS modeling functions.

Examples

if (requireNamespace("sf", quietly = TRUE)) {
  locs <- locs_from_sf(sf::st_as_sf(
    data.frame(site = "a", axis1 = 1, axis2 = 0, lon = -110, lat = 39),
    coords = c("lon", "lat"),
    crs = 4326
  ))
}