cellnumbers | R Documentation |
Provide the 'cellnumbers' capability of raster::extract and friends directly, returning a data frame of query-object identifiers 'object_' and the cell number.
cellnumbers(x, query, ...)
## Default S3 method:
cellnumbers(x, query, ...)
## S3 method for class 'SpatialLines'
cellnumbers(x, query, ...)
## S3 method for class 'sfc'
cellnumbers(x, query, ...)
## S3 method for class 'sf'
cellnumbers(x, query, ...)
x |
Raster object |
query |
Spatial object or matrix of coordinates |
... |
unused |
Raster data is inherently 2-dimensional, with a time or 'level' dimension treated like a layers of these 2D forms. The 'raster' package cell number is counted from 1 at the top-left, across the rows and down. This corresponds the the standard "raster graphics" convention used by 'GDAL' and the 'sp' package, and many other implementations. Note that this is different to the convention used by the graphics::image function.
Currently this function only operates as if the input is a single layer objects, it's not clear if adding an extra level of grouping for layers would be sensible.
a data frame (tibble) with columns
object_
- the object ID (what row is it from the spatial object)
cell_
- the cell number of the raster
library(raster)
library(dplyr)
r <- raster(volcano) %>% aggregate(fact = 4)
cellnumbers(r, rasterToContour(r, level = 120))
library(dplyr)
cr <- cut(r, pretty(values(r)))
suppressWarnings(tt <- cellnumbers(cr, polycano))
library(dplyr)
tt %>% mutate(v = extract(r, cell_)) %>%
group_by(object_) %>%
summarize(mean(v))
head(pretty(values(r)), -1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.