Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

st_as_stars

convert objects into a stars object


Description

convert objects into a stars object

Usage

st_as_stars(.x, ...)

## S3 method for class 'list'
st_as_stars(.x, ..., dimensions = NULL)

## Default S3 method:
st_as_stars(.x = NULL, ..., raster = NULL)

## S3 method for class 'stars'
st_as_stars(.x, ..., curvilinear = NULL, crs = st_crs(4326))

## S3 method for class 'bbox'
st_as_stars(
  .x,
  ...,
  nx,
  ny,
  dx = dy,
  dy = dx,
  xlim = .x[c("xmin", "xmax")],
  ylim = .x[c("ymin", "ymax")],
  values = 0,
  n = 64800,
  pretty = FALSE,
  inside = FALSE,
  nz
)

## S3 method for class 'sf'
st_as_stars(.x, ..., name = attr(.x, "sf_column"))

## S3 method for class 'Raster'
st_as_stars(.x, ..., att = 1, ignore_file = FALSE)

## S3 method for class 'ncdfgeom'
st_as_stars(.x, ..., sf_geometry = NA)

## S3 method for class 'stars_proxy'
st_as_stars(
  .x,
  ...,
  downsample = 0,
  url = attr(.x, "url"),
  envir = parent.frame()
)

## S3 method for class 'data.frame'
st_as_stars(
  .x,
  ...,
  dims = coords,
  xy = dims[1:2],
  y_decreasing = TRUE,
  coords = 1:2
)

## S3 method for class 'xts'
st_as_stars(.x, ..., dimensions)

## S3 method for class 'OpenStreetMap'
st_as_stars(.x, ..., as_col = FALSE)

Arguments

.x

object to convert

...

in case .x is of class bbox, arguments passed on to pretty

dimensions

object of class dimensions

raster

character; the names of the dimensions that denote raster dimensions

curvilinear

only for creating curvilinear grids: named length 2 list holding longitude and latitude matrices; the names of this list should correspond to raster dimensions referred to

crs

object of class crs with the coordinate reference system of the values in curvilinear; see details

nx

integer; number of cells in x direction; see details

ny

integer; number of cells in y direction; see details

dx

numeric; cell size in x direction; see details

dy

numeric; cell size in y direction; see details

xlim

length 2 numeric vector with extent (min, max) in x direction

ylim

length 2 numeric vector with extent (min, max) in y direction

values

value(s) to populate the raster values with

n

the (approximate) target number of grid cells

pretty

logical; should cell coordinates have pretty values?

inside

logical; should all cells entirely fall inside the bbox, potentially not covering it completely?

nz

integer; number of cells in z direction; if missing no z-dimension is created.

name

character; name for the geometry dimensions

att

see factorValues; column in the RasterLayer's attribute table

ignore_file

logical; if TRUE, ignore the Raster object file name

sf_geometry

sf data.frame with geometry and attributes to be added to stars object. Must have same number of rows as timeseries instances.

downsample

integer: if larger than 0, downsample with this rate (number of pixels to skip in every row/column); if length 2, specifies downsampling rate in x and y.

url

character; URL of the stars endpoint where the data reside

envir

environment to resolve objects in

dims

the column names or indices that form the cube dimensions

xy

the x and y raster dimension names or indices; only takes effect after dims has been specified

y_decreasing

logical; if TRUE, (numeric) y values get a negative delta (decrease with increasing index)

coords

same as dims, for symmetry with st_as_sf

as_col

logical; return rgb numbers (FALSE) or (character) color values (TRUE)?

Details

if curvilinear is a stars object with longitude and latitude values, its coordinate reference system is typically not that of the latitude and longitude values.

For the bbox method: if pretty is TRUE, raster cells may extend the coordinate range of .x on all sides. If in addition to nx and ny, dx and dy are also missing, these are set to a single value computed as sqrt(diff(xlim)*diff(ylim)/n). If nx and ny are missing, they are computed as the ceiling of the ratio of the (x or y) range divided by (dx or dy), unless inside is TRUE, in which case ceiling is replaced by floor. Postive dy will be made negative. Further named arguments (...) are passed on to pretty.

For the ncdfgeom method: objects are point-timeseries with optional line or polygon geometry for each timeseries specified with the sf_geometry parameter. See ncdfgeom for more about this NetCDF-based format for geometry and timeseries.

for the xts methods, if dimensions are provided, time has to be the first dimension.

Examples

data(Produc, package = "plm")
st_as_stars(Produc, y_decreasing = FALSE)

stars

Spatiotemporal Arrays, Raster and Vector Data Cubes

v0.5-2
Apache License
Authors
Edzer Pebesma [aut, cre] (<https://orcid.org/0000-0001-8049-7069>), Michael Sumner [ctb] (<https://orcid.org/0000-0002-2471-7511>), Etienne Racine [ctb], Adriano Fantini [ctb], David Blodgett [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.