Package 'zonal'

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

Help Index


Aggregate data between zones Provides the ability to take attributes from one scale of polygon and split aggregate them to another.

Description

Aggregate data between zones Provides the ability to take attributes from one scale of polygon and split aggregate them to another.

Usage

aggregate_zones(
  data,
  geom,
  crosswalk,
  ID = "divide_id",
  fun = "mean",
  join = TRUE,
  drop = NULL
)

Arguments

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

Details

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.

Value

data.frame or sf object


Geometric Mean Summary

Description

Geometric Mean Summary

Usage

circular_mean(value, coverage_fraction)

Arguments

value

vector of value

coverage_fraction

coverage fraction

Value

data.frame


Distribution Summary

Description

Distribution Summary

Usage

distribution(value, coverage_fraction, breaks = 10, constrain = FALSE)

Arguments

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?

Value

data.frame


exactextractr Function Lookup

Description

exactextractr Function Lookup

Usage

ee_functions()

Value

data.frame


Equal Area Distribution

Description

Equal Area Distribution

Usage

equal_population_distribution(value, coverage_fraction, groups = 4)

Arguments

value

vector of value

coverage_fraction

coverage fraction

groups

number of intervals to create

Value

data.frame


Execute Zonal Stats

Description

Execute Zonal Stats

Usage

execute_zonal(
  data = NULL,
  geom = NULL,
  w = NULL,
  ID = NULL,
  fun = "mean",
  subds = 0,
  progress = FALSE,
  join = TRUE,
  drop = NULL,
  ...
)

Arguments

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

Value

sf object or data.table


Geometric Mean Summary

Description

Geometric Mean Summary

Usage

geometric_mean(x, coverage_fraction)

Arguments

x

vector of value

coverage_fraction

coverage fraction

Value

data.frame


Mode Summary

Description

Mode Summary

Usage

mode(x, coverage_fraction)

Arguments

x

vector of value

coverage_fraction

coverage fraction

Value

data.frame


Prep Incoming Data

Description

Prep Incoming Data

Usage

prep_geom(geom, crs = NULL)

Arguments

geom

sf or SpatVector object

crs

coordinate reference system

Value

SpatVector


Prep Incoming Data

Description

Prep Incoming Data

Usage

prep_input(data, subds = 0, lyrs = NULL, win = NULL)

Arguments

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)

Value

SpatRaster


Sanitize Column Inclusions

Description

Sanitize Column Inclusions

Usage

sanitize(exe, drop = NULL)

Arguments

exe

executed zonal product

drop

colnames to drop from table

Value

data.table


Extract and Transform Time Series Data

Description

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.

Usage

ts_extract(output, ID)

Arguments

output

A data frame containing the time series data in wide format. It must have a column with the name matching ID and other columns with names in the format "description_Date" (e.g., "temp_2024-01-01").

ID

A character string specifying the column name that uniquely identifies rows in the dataset.

Value

A transformed data frame with the following changes:

description

The variable names extracted from the original column names.

Date

A Date column converted from the original column names.

value

The associated values for each combination of ID, description, and Date.


Weight Function Lookup

Description

Weight Function Lookup

Usage

weight_functions()

Value

data.frame


Build Weighting Grid

Description

Returns a data.table with columns for ID, grid_id, X, Y and weight. By default this object is sorted on the grid_id

Usage

weight_grid(data, geom, ID, progress = TRUE)

Arguments

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

Value

a list(data.table, vector)


Use Weight Grid to extract SpatRast Data

Description

Returns a data.table with raster data attached to weight grid

Usage

weight_grid_to_data(data, w, subds = 0)

Arguments

data

SpatRaster or file path

w

weight grid

subds

subdatasets to extract

Value

data.table


Execute Zonal Stats by ExactExtract

Description

execute exactextract more flexiably

Usage

zone_by_ee(
  data,
  geom,
  ID,
  fun = "mean",
  subds = 0,
  progress = FALSE,
  join = TRUE,
  ...
)

Arguments

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

Value

data.table


Execute Zonal Stats by Weight Grid

Description

execute

Usage

zone_by_weights(data, w, ID, fun = "mean", subds = 0, ...)

Arguments

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

Value

data.table