st_xy2sfc: replace x y raster dimensions with simple feature geometry...

View source: R/sf.R

st_xy2sfcR Documentation

replace x y raster dimensions with simple feature geometry list (points, or polygons = rasterize) and vice versa

Description

replace x y raster dimensions with simple feature geometry list (points, or polygons = rasterize) and vice versa

Usage

st_xy2sfc(x, as_points, ..., na.rm = TRUE)

st_sfc2xy(x, ...)

Arguments

x

object of class stars, or of class sf

as_points

logical; if TRUE, generate points at cell centers, else generate polygons

...

for 'st_xy2sfc': arguments passed on to st_as_sfc, for 'st_sfc2xy' arguments passed on to st_as_stars.data.frame

na.rm

logical; omit (remove) cells which are entirely missing valued (across other dimensions)?

Details

'st_xy2sfc' replaces x y raster dimensions with simple feature geometry list (points, or polygons = rasterize)

'st_sfc2xy' replaces POINT simple feature geometry list with an x y raster

Value

'st_xy2sfc' returns an object of class stars with x and y raster dimensions replaced by a single sfc geometry list column containing either points, or polygons. Adjacent cells with identical values are not merged; see st_rasterize for this.

'st_sfc2xy' returns an object of class stars with a POINT list replaced by X and Y raster dimensions. This only works when the points are distributed over a regular or rectilinear grid.

Examples

(reduced_nc = read_ncdf(system.file("nc/reduced.nc", package = "stars")))
(x = stars::st_xy2sfc(reduced_nc, as_points = TRUE, na.rm = FALSE))
# roundtrip:
st_sfc2xy(x, dims=c("X", "Y","zlev","time"))

r-spatial/stars documentation built on Feb. 19, 2025, 12:04 a.m.