Tidy Tools for 'Raster' Data

Facilities to work with vector and raster data in efficient repeatable and systematic work flow. Missing functionality in existing packages is included here to allow extraction from raster data with 'simple features' and 'Spatial' types and to make extraction consistent and straightforward. Extract cell numbers from raster data and return the cells, values and weights as a data frame rather than as lists of matrices or vectors. The functions here allow spatial data to be used without special handling for the format currently in use.


Travis-CI BuildStatus AppVeyor buildstatus CoverageStatus CRAN_Status_Badge CRAN RStudio mirrordownloads

The raster package is extremely powerful for spatial data. It provides very efficient data extraction and summary tools via consistent cell-index and comprehensive set of functions for working with grids, cells and their values.

Tabularaster provides some more helpers for working with cells and tries to fill some of the (very few!) gaps in raster functionality. When raster returns cell values of hierarchical objects it returns a hierarchical (list) of cells to match the input query, while tabularaster::cellnumbers instead returns a data frame of identifiers and cell numbers.

Tabularaster provides these functions.

  • as_tibble - convert to data frame with options for value column and cell, dimension and date indexing
  • cellnumbers - extract of cell index numbers as a simple data frame with “object ID” and “cell index”
  • index_extent - create an index extent, essentially extent(0, ncol(raster), 0, nrow(raster))

All functions that work with sp Spatial also work with `sf simple features.

There is some overlap with quadmesh and spex while I figure out where things belong.

Installation

Install from CRAN,

install.packages("tabularaster")

or get the development version from Github.

devtools::install_github("hypertidy/tabularaster")

Usage

Basic usage is to extract the cell numbers from an object, where object is a a matrix of points, a Spatial object or a simple features sf object.

cells <- cellnumbers(raster, object)

The value in this approach is not for getting cell numbers per se, but for using those downstream. The cell number is an index into the raster that means the geometric hard work is done, so we can apply the index for subsequent extractions, grouping aggregations, or for determining the coordinates or other structure summaries of where the cell belongs.

E.g.

 
## summarize by object grouping
cells %>% mutate(value= extract(raster, cell_)) %>% group_by(object_) %>% summarize(mean(value))
 
## summarize by cell grouping
cells %>% mutate(value= extract(raster, cell_)) %>% group_by(cell_) %>% summarize(mean(value))

The utility of this is very much dependent on individual workflow, so this in its own right is not very exciting. Tabularaster simply provides an easier way to create your tools.

See the vignettes for more.

News

tabularaster dev

  • Function cellnumbers now provides only basic cell lookup, the weights and other options available in raster functions are ignored.

  • Function extentFromCells is now imported from raster and re-exported.

  • Now applying fasterize for sf polygon objects, and spatstat for sf line objects for very significant speed ups.

  • Now import spatstat for faster line rasterization.

tabularaster 0.4.0

  • add xy argument to as_tibble

  • fix missing vignette knitr reference

  • new oisst data set

tabularaster 0.3.0

  • bufext made defunct

  • added index extent functions index_extent and cellsFromExtent

  • removed decimate function

  • fixed unnecessary lapply call for the points case, so that is now not slow

  • extra handling for as_tibble, value is now optional so that data-less rasters can be used to build cell and dimension indices

  • new vignette stub to list all relevant raster functions

  • object_ is now integer, 1-based to match the rows in query

  • removed boundary (see romsboundary in angstroms)

  • consolidated on the central tools, removed experiments

  • migrated the buffer extent logic to spex, deprecated bufext

  • added as_tibble for rasters

  • added boundary function

tidyraster 0.2.0

  • new data sets rastercano and polycano

  • new functions decimate, cellnumbers and bufext

  • Added a NEWS.md file to track changes to the package.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("tabularaster")

0.5.0 by Michael D. Sumner, 8 months ago


https://github.com/hypertidy/tabularaster


Report a bug at https://github.com/hypertidy/tabularaster/issues


Browse source code at https://github.com/cran/tabularaster


Authors: Michael D. Sumner [aut, cre]


Documentation:   PDF Manual  


GPL-3 license


Imports dplyr, methods, raster, sp, spatstat, spex, spbabel, tibble, viridis, gibble, fasterize, magrittr, rlang

Suggests covr, testthat, knitr, rmarkdown, sf, spdplyr


See at CRAN