Learn R Programming

stars (version 0.7-0)

st_xy2sfc: 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, ...)

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.

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

Examples

Run this code
(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"))

Run the code above in your browser using DataLab