MyNixOS website logo
Description

Fast Multiscale Raster Extraction and Moving Window Analysis with FFT.

Provides fast moving-window ("focal") and buffer-based extraction for raster data using the 'terra' package. Automatically selects between a 'C++' backend (via 'terra') and a Fast Fourier Transform (FFT) backend depending on problem size. The FFT backend supports sum and mean, while other statistics (e.g., median, min, max, standard deviation) are handled by the 'terra' backend. Supports multiple kernel types (e.g., circle, rectangle, gaussian), with NA handling consistent with 'terra' via 'na.rm' and 'na.policy'. Operates on 'SpatRaster' objects and returns results with the same geometry.

fastfocal

CRAN Status R-CMD-check DOI

fastfocal: Fast Multi-scale Raster Extraction and Moving Window Analysis with Fast Fourier Transform (FFT) in R

fastfocal provides high-performance, flexible raster smoothing and extraction functions in R using moving windows, buffer-based zones, and an auto-switching FFT backend for large kernels. It supports multiple focal statistics and allows users to work at multiple spatial scales with ease.


Installation

Once accepted on CRAN, you will be able to install the stable release with:

install.packages("fastfocal")

Until then, you can install the development version from GitHub:

# install.packages("remotes")
remotes::install_github("hoyiwan/fastfocal")

Overview

This package includes:

  • fastfocal() — fast moving-window smoothing with support for mean, sum, min, max, sd, and median
  • fastextract() — fast extraction of raster values at point or buffer locations
  • fastfocal_weights() — utility for generating spatial weight matrices (circular, Gaussian, etc.)
  • Auto-switch backend to FFT for large windows to improve performance
    • FFT backend currently supports sum and mean; other statistics use the terra backend
  • Native support for terra::SpatRaster and terra::SpatVector objects

Example Usage

library(fastfocal)
library(terra)

# Create a dummy raster
r <- rast(nrows = 100, ncols = 100, xmin = 0, xmax = 3000, ymin = 0, ymax = 3000)
values(r) <- runif(ncell(r))

# Apply fast focal smoothing with circular window of radius 300
smoothed <- fastfocal(r, d = 300, w = "circle", fun = "mean")

# Plot the result
plot(smoothed)

Weighted extraction at points:

# Create SpatVector of points
pts <- vect(data.frame(x = c(500, 1500), y = c(500, 2500)), geom = c("x", "y"), crs = crs(r))

# Extract raster values in 500 m buffers around points
result <- fastextract(r, pts, d = 500, fun = "mean")
print(result)

Vignettes

You can also access them from R using:

vignette("index", package = "fastfocal")

License

This package is licensed under the MIT License (see the LICENSE file).


Citation

If you use fastfocal in published work, please cite it as:

Ho Yi Wan (2025). fastfocal: A fast, energy-efficient R package for focal raster operations. Version v0.1.1. Zenodo. https://doi.org/10.5281/zenodo.17074691

Or use the BibTeX entry:

@software{wan_fastfocal_2025,
  author       = {Ho Yi Wan},
  title        = {fastfocal: A fast, energy-efficient R package for focal raster operations},
  version      = {v0.1.3},
  year         = {2025},
  publisher    = {Zenodo},
  doi          = {10.5281/zenodo.17074691},
  url          = {https://doi.org/10.5281/zenodo.17074691}
}

You can also run:

citation("fastfocal")

Author

Ho Yi Wan
[email protected]


Purpose

Built to support large-scale ecological analysis, high-performance raster processing, and reproducible landscape research workflows.

Metadata

Version

0.1.3

License

Unknown

Platforms (76)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows