Skip to content
R package for fast and accurate raster zonal statistics
Branch: master
Clone or download
Latest commit 44bc269 Jun 18, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R Fix passing of XY to callback Sep 5, 2018
src Update path to static GEOS library [Windows] Jun 18, 2019
tests Add test showing behavior when polygon covers NA cells Dec 18, 2018
tools Make buildable on Windows Jun 13, 2018
.Rbuildignore Initial commit Jun 12, 2018
.gitignore Use autoconf to pull flags from geos-config Nov 15, 2018
.gitlab-ci.yml Test against R-devel in GitLab CI Jan 20, 2019
DESCRIPTION Update DESCRIPTION to get correct pkgdown output Dec 19, 2018
LICENSE Squashed 'src/exactextract/' content from commit 4495ec8 Jun 12, 2018
NAMESPACE Initial commit Jun 12, 2018
README.md Fix typo Apr 29, 2019
cleanup Use autoconf to pull flags from geos-config Nov 15, 2018
configure Use autoconf to pull flags from geos-config Nov 15, 2018
configure.ac
exactextractr.Rproj Initial commit Jun 12, 2018

README.md

exactextractr

Build Status

This package provides routines to perform fast and accurate zonal statistics on raster and sf objects in R using the exactextract library. Relative to other implementations, such as the extract function in the raster package, it:

  • computes the exact percentage of each raster cell that is covered by a polygon
  • avoids the use of computationally expensive raster disaggregation or polygon clipping methods

Additional background and a description of the method is available here.

Example

require(raster)
require(sf)
require(exactextractr)

# Pull some administrative boundaries for Brazil
brazil <- st_as_sf(getData('GADM', country='BRA', level=2))

# Pull some climate data (max. temperature)
temp <- getData('worldclim', var='tmax', res=10)[[12]]

# Find the mean-max temperature for each administrative boundary
brazil$max_dec_temp <- exact_extract(temp, brazil, weighted.mean, na.rm=TRUE)

plot(brazil['max_dec_temp'])

# Output a matrix of cell values, cell coordinates, and coverage fractions for a given polygon
exact_extract(temp, brazil[1, ], include_xy=TRUE)

# Generate a raster showing cell coverage fractions for a given polygon
can <- st_as_sf(getData('GADM', country='CAN', level=0))
plot(partial_mask(temp, can)[[1]])

Dependencies

Installation requires the GEOS geometry processing library. For best performance, it is recommended to use version 3.7, which introduced some optimizations important to exactextractr. On Windows, GEOS will be downloaded automatically as part of package install. On MacOS, it can be installed using Homebrew (brew install geos). On Linux, it can be installed from system package repositories (apt-get install libgeos-dev on Debian/Ubuntu, or yum install libgeos-devel on CentOS/RedHat.)

On Windows, the R build tools (Rtools) are also necessary.

Installation

exactextractr is not in CRAN and can be installed from source only. Using devtools, the package can be installed with:

devtools::install_github('isciences/exactextractr')

Limitations

  • Raster and polygon inputs must be in the same coordinate reference system.
  • The portion of the raster that intersects any given polygon must fit into memory. (The entire raster does not need to fit into memory.)
You can’t perform that action at this time.