mbedward / focalutils

Utility functions to create focal matrices and work with compass bearings

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

focalutils

An R package that provides a function (make_focal_matrix) to create matrices of circular or sector neighbourhoods for use with the focal function in the terra package. It also includes a few utility functions to work with compass bearings such as converting bearings to and from Cartesian angles and determining the direction and angle of the shortest rotation between two bearings.

Installation

install.packages("remotes") # if you don't already have it
remotes::install_github("mbedward/focalutils")

Examples

Create a circular focal matrix of radius 50 cells, where neighbourhood cells have a value of 1 and outside cells have NA:

library(focalutils)
m <- make_focal_matrix(50)
plot_focal_matrix(m)

Create the same neighbourhood but exclude the centre cell:

m <- make_focal_matrix(50, include_centre = FALSE)
plot_focal_matrix(m)

Create a sector neighbourhood spanning 90 degrees and facing west:

m <- make_focal_matrix(50, start_bearing = 225, end_bearing = 315)
plot_focal_matrix(m)

Create the complement of the last neighbourhood: a circular neighbourhood that excludes the 90 degree sector facing west (Pacman!)

m <- make_focal_matrix(50, start_bearing = 315, end_bearing = 225)
plot_focal_matrix(m)

About

Utility functions to create focal matrices and work with compass bearings

License:Other


Languages

Language:R 100.0%