Jan 17, 2019
sf
, by both users and developersst_intersects
, st_intersection
etc.geom_sf
is now in ggplot2
, and takes care of (re)projecting incompatible layerssuppressPackageStartupMessages(library(tidyverse)) suppressPackageStartupMessages(library(sf)) system.file("gpkg/nc.gpkg", package="sf") %>% read_sf -> nc nc2 <- nc %>% select(SID74, SID79) %>% gather(VAR, SID, -geom) ggplot() + geom_sf(data = nc2, aes(fill = SID)) + facet_wrap(~VAR, ncol = 1)
tidyr::gather
)sf
has no raster support, no solid vector \(\leftrightarrow\) raster integrationData cubes are array data where values (or records) are given for each combination of the dimension values. Examples:
base
and dplyr
base::array
has powerfull infrastructure for this:
dimnames
to label dimension values (only character
)apply
: apply functions to a dimension or sets of dimensions[
subsetting (slice, crop)abind::
abind
, aperm
, adrop
dplyr::tbl_cube
has some further support
base::array
s with measurementsDate
or POSIXct
dimension valuesfilter
on array dimensions, and group_by
aggregationssfc
)stars
stars
data cubes have as special case
and further
tbl_cube
: a list of arrays and a set of dimensionsunits
, coordinate reference systems (PROJ)stars_proxy
), andsuppressPackageStartupMessages(library(stars)) library(viridis) ## Loading required package: viridisLite system.file("tif/L7_ETMs.tif", package = "stars") %>% read_stars() -> x ggplot() + geom_stars(data = x) + coord_equal() + facet_wrap(~band) + theme_void() + scale_fill_viridis() + scale_x_discrete(expand=c(0,0)) + scale_y_discrete(expand=c(0,0))
r = read_stars(s2, proxy = TRUE) dim(r) ## x y band ## 10980 10980 4 plot(r)
# S2 10m: band 4: near infrared, band 1: red. ndvi = function(x) (x[4]-x[1])/(x[4] + x[1]) system.time(s2.ndvi <- st_apply(r, c("x", "y"), ndvi)) ## user system elapsed ## 0 0 0 plot(s2.ndvi) # modifies execution order: reads downsampled, computes ndvi, plots
Cloud proxy:
Data cube view:
st_intersects
only counts hits, and ignores length/duration/strengthsf
we extended tables to spatial tablesstars
we extend that to raster and vector data cubes, including spatial time series as special casestars
can do out-of-core raster, is lazy, will address cloud rasters processing