Title: | Performant zonal statistics over flexible units |
---|---|
Description: | Given gridded and vector based input, compute summary statistics. |
Authors: | Mike Johnson [aut, cre] |
Maintainer: | Mike Johnson <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.1 |
Built: | 2024-12-06 04:31:37 UTC |
Source: | https://github.com/mikejohnson51/zonal |
Aggregate data between zones Provides the ability to take attributes from one scale of polygon and split aggregate them to another.
aggregate_zones( data, geom, crosswalk, ID = "divide_id", fun = "mean", join = TRUE, drop = NULL )
aggregate_zones( data, geom, crosswalk, ID = "divide_id", fun = "mean", join = TRUE, drop = NULL )
data |
tabular data reference to the smaller unit |
geom |
sf, sfc, SpatialPolygonsDataFrame, or SpatialPolygons object with polygonal geometries |
crosswalk |
a crosswalk of smaller unit to major unit relations |
ID |
the grouping ID |
fun |
an optional function or character vector, as described below |
join |
if TRUE the geom will be joined to the results |
drop |
colnames to drop from table |
the cross walk table must have at least 4 columns containing the ID and areas of the small units and
and the ID and areas of the large unit. The name of the large unit IDs is provided by the ID
parameter in the function
signature. The smaller unit IDs must have a corresponding attribute in the data input. The area of the larger units must be called
areasqkm
, while the area of the smaller units must be called s_areasqkm.
data.frame or sf object
Geometric Mean Summary
circular_mean(value, coverage_fraction)
circular_mean(value, coverage_fraction)
value |
vector of value |
coverage_fraction |
coverage fraction |
data.frame
Distribution Summary
distribution(value, coverage_fraction, breaks = 10, constrain = FALSE)
distribution(value, coverage_fraction, breaks = 10, constrain = FALSE)
value |
vector of value |
coverage_fraction |
coverage fraction |
breaks |
either a numeric vector of two or more unique cut points or a single number (greater than or equal to 2) giving the number of intervals into which x is to be cut. (default = 10) |
constrain |
should breaks (with length > 1) be limited by the max of value? |
data.frame
exactextractr Function Lookup
ee_functions()
ee_functions()
data.frame
Equal Area Distribution
equal_population_distribution(value, coverage_fraction, groups = 4)
equal_population_distribution(value, coverage_fraction, groups = 4)
value |
vector of value |
coverage_fraction |
coverage fraction |
groups |
number of intervals to create |
data.frame
Execute Zonal Stats
execute_zonal( data = NULL, geom = NULL, w = NULL, ID = NULL, fun = "mean", subds = 0, progress = FALSE, join = TRUE, drop = NULL, ... )
execute_zonal( data = NULL, geom = NULL, w = NULL, ID = NULL, fun = "mean", subds = 0, progress = FALSE, join = TRUE, drop = NULL, ... )
data |
SpatRaster or file path |
geom |
sf, sfc object with polygonal geometries |
w |
a weight grid (produced with weight_grid) |
ID |
the grouping ID |
fun |
an optional function or character vector, as described below |
subds |
character or boolean to select a sub-dataset. If NULL all are selected |
progress |
if TRUE, display a progress bar during processing |
join |
if TRUE the geom will be joined to the results |
drop |
colnames to drop from table |
... |
optional arguments to pass fun |
sf object or data.table
Geometric Mean Summary
geometric_mean(x, coverage_fraction)
geometric_mean(x, coverage_fraction)
x |
vector of value |
coverage_fraction |
coverage fraction |
data.frame
Mode Summary
mode(x, coverage_fraction)
mode(x, coverage_fraction)
x |
vector of value |
coverage_fraction |
coverage fraction |
data.frame
Prep Incoming Data
prep_geom(geom, crs = NULL)
prep_geom(geom, crs = NULL)
geom |
sf or SpatVector object |
crs |
coordinate reference system |
SpatVector
Prep Incoming Data
prep_input(data, subds = 0, lyrs = NULL, win = NULL)
prep_input(data, subds = 0, lyrs = NULL, win = NULL)
data |
SpatRaster, file path, raster |
subds |
positive integer or character to select a sub-dataset. If zero or "", all sub-datasets are returned (if possible) |
lyrs |
positive integer or character to select a subset of layers (a.k.a. "bands") |
win |
SpatExtent to set a window (area of interest) |
SpatRaster
Sanitize Column Inclusions
sanitize(exe, drop = NULL)
sanitize(exe, drop = NULL)
exe |
executed zonal product |
drop |
colnames to drop from table |
data.table
This function processes an input dataset by reshaping it from wide to long format, separating columns into descriptions and dates, and renaming the resulting dataset for further analysis.
ts_extract(output, ID)
ts_extract(output, ID)
output |
A data frame containing the time series data in wide format. It must have a column with the name matching |
ID |
A character string specifying the column name that uniquely identifies rows in the dataset. |
A transformed data frame with the following changes:
The variable names extracted from the original column names.
A Date
column converted from the original column names.
The associated values for each combination of ID
, description
, and Date
.
Weight Function Lookup
weight_functions()
weight_functions()
data.frame
Returns a data.table with columns for ID, grid_id, X, Y and weight. By default this object is sorted on the grid_id
weight_grid(data, geom, ID, progress = TRUE)
weight_grid(data, geom, ID, progress = TRUE)
data |
file path or |
geom |
sf, sfc, SpatialPolygonsDataFrame, or SpatialPolygons object with polygonal geometries |
ID |
the name of the column providing the unique identified of each geom |
progress |
if TRUE, display a progress bar during processing |
a list(data.table, vector)
Returns a data.table with raster data attached to weight grid
weight_grid_to_data(data, w, subds = 0)
weight_grid_to_data(data, w, subds = 0)
data |
SpatRaster or file path |
w |
weight grid |
subds |
subdatasets to extract |
data.table
execute exactextract more flexiably
zone_by_ee( data, geom, ID, fun = "mean", subds = 0, progress = FALSE, join = TRUE, ... )
zone_by_ee( data, geom, ID, fun = "mean", subds = 0, progress = FALSE, join = TRUE, ... )
data |
SpatRaster or file path |
geom |
summary units |
ID |
the grouping ID |
fun |
summarization function |
subds |
subdatasets to extract |
progress |
if TRUE, display a progress bar during processing |
join |
should data be joined to geom? |
... |
additional arguments passed on to exact_extract |
data.table
execute
zone_by_weights(data, w, ID, fun = "mean", subds = 0, ...)
zone_by_weights(data, w, ID, fun = "mean", subds = 0, ...)
data |
SpatRaster or file path |
w |
weight grid |
ID |
the grouping ID |
fun |
summarization function |
subds |
subdatasets to extract |
... |
additional arguments passed on to the lapply summary in DT summary |
data.table