`R/stars.R`

, `R/sf.R`

, `R/raster.R`

, and 5 more
`st_as_stars.Rd`

convert objects into a stars object

```
st_as_stars(.x, ...)
# S3 method for list
st_as_stars(.x, ..., dimensions = NULL)
# S3 method for default
st_as_stars(.x = NULL, ..., raster = NULL)
# S3 method for stars
st_as_stars(.x, ..., curvilinear = NULL, crs = st_crs(4326))
# S3 method for 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,
proxy = FALSE
)
# S3 method for sf
st_as_stars(.x, ..., name = attr(.x, "sf_column"))
# S3 method for Raster
st_as_stars(.x, ..., att = 1, ignore_file = FALSE)
# S3 method for SpatRaster
st_as_stars(
.x,
...,
ignore_file = FALSE,
as_attributes = all(terra::is.factor(.x))
)
# S3 method for ncdfgeom
st_as_stars(.x, ..., sf_geometry = NA)
# S3 method for stars_proxy
st_as_stars(
.x,
...,
downsample = 0,
url = attr(.x, "url"),
envir = parent.frame()
)
# S3 method for data.frame
st_as_stars(
.x,
...,
dims = coords,
xy = dims[1:2],
y_decreasing = TRUE,
coords = 1:2
)
# S3 method for xts
st_as_stars(.x, ..., dimensions, name = "attr")
# S3 method for OpenStreetMap
st_as_stars(.x, ..., as_col = FALSE)
```

- .x
object to convert

- ...
in case

`.x`

is of class`bbox`

, arguments passed on to pretty. In case`.x`

is of class`nc_proxy`

, arguments passed on to`read_ncdf`

.- 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 or object of class units; cell size in x direction; see details

- dy
numeric or object of class units; 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 (

`TRUE`

), or allways cover the bbox (`FALSE`

), or find a good approximation (`NA`

, default)?- nz
integer; number of cells in z direction; if missing no z-dimension is created.

- proxy
logical; should a

`stars_proxy`

object be created? (requires gdal_create binary when sf < 1.0-6)- name
character; attribute name for array from an

`xts`

object- att
see factorValues; column in the RasterLayer's attribute table

- ignore_file
logical; if

`TRUE`

, ignore the SpatRaster object file name- as_attributes
logical; if

`TRUE`

and`.x`

has more than one layer, load these as separate attributes rather than as a band or time dimension (only implemented for the case where`ignore_file`

is`TRUE`

)- 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)?

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, floor, or rounded to integer value) of the ratio of the (x or y) range divided by (dx or dy), depending on the value of `inside`

. Positive `dy`

will be made negative. Further named arguments (`...`

) are passed on to `pretty`

. If `dx`

or `dy`

are `units`

objects, their value is converted to the units of `st_crs(.x)`

(only when sf >= 1.0-7).

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.

```
if (require(plm, quietly = TRUE)) {
data(Produc, package = "plm")
st_as_stars(Produc, y_decreasing = FALSE)
data(Produc, package = "plm")
st_as_stars(Produc, y_decreasing = FALSE)
}
#>
#> Attaching package: ‘plm’
#> The following objects are masked from ‘package:dplyr’:
#>
#> between, lag, lead
#> stars object with 2 dimensions and 9 attributes
#> attribute(s):
#> region pcap hwy water
#> 5 :136 Min. : 2627 Min. : 1827 Min. : 228.5
#> 8 :136 1st Qu.: 7097 1st Qu.: 3858 1st Qu.: 764.5
#> 4 :119 Median : 17572 Median : 7556 Median : 2266.5
#> 1 :102 Mean : 25037 Mean :10218 Mean : 3618.8
#> 3 : 85 3rd Qu.: 27692 3rd Qu.:11267 3rd Qu.: 4318.7
#> 6 : 68 Max. :140217 Max. :47699 Max. :24592.3
#> (Other):170
#> util pc gsp emp
#> Min. : 538.5 Min. : 4053 Min. : 4354 Min. : 108.3
#> 1st Qu.: 2488.3 1st Qu.: 21651 1st Qu.: 16502 1st Qu.: 475.0
#> Median : 7008.8 Median : 40671 Median : 39987 Median : 1164.8
#> Mean :11199.5 Mean : 58188 Mean : 61014 Mean : 1747.1
#> 3rd Qu.:11598.5 3rd Qu.: 64796 3rd Qu.: 68126 3rd Qu.: 2114.1
#> Max. :80728.1 Max. :375342 Max. :464550 Max. :11258.0
#>
#> unemp
#> Min. : 2.800
#> 1st Qu.: 5.000
#> Median : 6.200
#> Mean : 6.602
#> 3rd Qu.: 7.900
#> Max. :18.000
#>
#> dimension(s):
#> from to offset delta refsys point values x/y
#> state 1 48 NA NA NA NA ALABAMA,...,WYOMING [x]
#> year 1 17 1969.5 1 NA NA NULL [y]
```