Learn R Programming

stars (version 0.2-0)

st_as_sf: Convert stars object into an sf object

Description

Convert stars object into an sf object

Usage

# S3 method for stars
st_as_sfc(x, ..., as_points,
  which = seq_len(prod(dim(x)[1:2])))

# S3 method for stars st_as_sf(x, ..., as_points = !merge, na.rm = TRUE, merge = has_raster(x) && !(is_curvilinear(x) || is_rectilinear(x)), use_integer = is.logical(x[[1]]) || is.integer(x[[1]]))

Arguments

x

object of class stars

...

ignored

as_points

logical; should cells be converted to points or to polygons? See details.

which

linear index of cells to keep (this argument is not recommended to be used)

na.rm

logical; should missing valued cells be removed, or also be converted to features?

merge

logical; if TRUE, cells with identical values are merged (using GDAL_Polygonize or GDAL_FPolygonize); if FALSE, a polygon for each raster cell is returned; see details

use_integer

(relevant only if merge is TRUE): if TRUE, before polygonizing values are rounded to 32-bits signed integer values (GDALPolygonize), otherwise they are converted to 32-bit floating point values (GDALFPolygonize).

Details

If merge is TRUE, only the first attribute is converted into an sf object. If na.rm is FALSE, areas with NA values are also written out as polygons.

Examples

Run this code
# NOT RUN {
tif = system.file("tif/L7_ETMs.tif", package = "stars")
x = read_stars(tif)
x = x[,,,6] # a band with lower values in it
x[[1]][x[[1]] < 30] = NA # set lower values to NA
x[[1]] = x[[1]] < 100 # make the rest binary
x
(p = st_as_sf(x)) # removes NA areas
plot(p, axes = TRUE)
(p = st_as_sf(x, na.rm = FALSE)) # includes polygons with NA values
plot(p, axes = TRUE)
# }

Run the code above in your browser using DataLab