/
README.Rmd
80 lines (49 loc) · 3.29 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
[![Travis-CI Build Status](https://travis-ci.org/hypertidy/tabularaster.svg?branch=master)](https://travis-ci.org/hypertidy/tabularaster)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/hypertidy/tabularaster?branch=master&svg=true)](https://ci.appveyor.com/project/mdsumner/tabularaster-sp94a)
[![Coverage Status](https://img.shields.io/codecov/c/github/hypertidy/tabularaster/master.svg)](https://codecov.io/github/hypertidy/tabularaster?branch=master)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/tabularaster)](https://cran.r-project.org/package=tabularaster)
[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/tabularaster)](http://www.r-pkg.org/pkg/tabularaster)
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# tabularaster
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,
```{r, eval=FALSE}
install.packages("tabularaster")
```
or get the development version from Github.
```{r, eval=FALSE}
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.
```{r eval=FALSE}
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.
```{r eval=FALSE}
## 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.