Fast raster extraction and manipulation in R

velox is an R package for performing fast extraction and manipulation operations on geospatial raster data. velox is fast because:

velox is fully interoperable with the raster, sp, and sf packages.

Travis-CI Build Status codecov CRAN Version r require(badger); badge_devel("hunzikp/velox", "green") CRAN Downloads


Optimized for speed

``` {r, echo = FALSE, warning = FALSE, message = FALSE}

Dependencies

library(velox) library(sf) library(raster) library(rasterVis)

Load data

nl.vx <- velox('nl.tif') sui.sf <- readRDS(file = 'sui.Rda')

Extract using vx

vx.time <- system.time(ex.mat <- nl.vx$extract(sp = sui.sf, fun = function(x) sum(x, na.rm = TRUE)))

Extract using raster

sui.sp <- as(st_zm(sui.sf), 'Spatial')

ras.time <- system.time(extract(x = nl.vx$as.RasterLayer(), sui.sp))

ras.time <- c(0,0,54.759)

``` {r, echo = FALSE, warning = FALSE, message = FALSE, fig.height = 2.75, fig.width = 4.5}
## Plot nightlights
lattice.options(axis.padding=list(factor=0.5))
nightPalette <- colorRampPalette(c("black", 
                                   rgb(4,6,84, maxColorValue=255),
                                   rgb(218,165,32, maxColorValue=255), 
                                   "white"), bias = 0.95)
par(mar = c(0,0,0,0))
image(log(nl.vx$as.RasterLayer()), col = nightPalette(25), axes = FALSE)
## Plot geometries
ar <- st_area(st_zm(sui.sf))
lnl <- log(as.vector(ex.mat)/as.vector(ar))  # Log nl per area
nightPalette <- colorRampPalette(c(rgb(4,6,84, maxColorValue=255),
                                   rgb(218,165,32, maxColorValue=255), 
                                   "white"), bias = 1)
col <- nightPalette(25)[as.numeric(cut(lnl, breaks = 25))]
par(bg = grey(0.25), mar = rep(0, 4), xaxs = "i", yaxs = "i")
plot(sui.sp, col = col, border = grey(0.1), lwd = 0.1)

Aggregating September 2017 nightlight emissions for 2268 Swiss communes takes r round(vx.time[3], 2) seconds in velox and r round(ras.time[3], 2) seconds in raster.


Features

velox currently offers the following features:



hunzikp/velox documentation built on June 6, 2021, 2:40 a.m.