fasterize

by ecohealthalliance

ecohealthalliance / fasterize

High performance raster conversion for modern spatial data πŸš€πŸŒβ–¦

141 Stars 15 Forks Last release: Not found Other 80 Commits 0 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

fasterize

Fast sf-to-raster conversion

Project Status: Active – The project has reached a stable, usable state and is being actively developed. MIT Licensed - Copyright 2016 EcoHealth Alliance Linux Build Status Windows Build status Coverage Status CRAN RStudio mirror downloads

fasterize is a high-performance replacement for the

rasterize()
function in the raster package.

Functionality is currently limited to rasterizing polygons in sf-type data frames.

Installation

Install the current version of fasterize from CRAN:

install.packages('fasterize')

Install the development version of fasterize with devtools:

devtools::install_github("ecohealthalliance/fasterize")

fasterize uses Rcpp and thus requires a compile toolchain to install from source. Testing (and most use) requires sf, which requires GDAL (>= 2.0.0), GEOS (>= 3.3.0), and PROJ.4 (>= 4.8.0) to be installed on your system.

Usage

The main function,

fasterize()
, takes the same inputs as
raster::rasterize()
but currently has fewer options and is is limited to rasterizing polygons.

A method for creating empty rasters from

sf
objects is provided, and raster plot methods are re-exported.
library(raster)
library(fasterize)
library(sf)
p1 

Performance

Let's compare

fasterize()
to
raster::rasterize()
:
pols_r 
#> Unit: milliseconds
#>       expr     min      lq    mean  median      uq    max neval cld
#>  rasterize 342.486 379.028 426.959 404.759 434.029 859.01   100   b
#>  fasterize   0.337   0.368   0.499   0.413   0.636   2.02   100  a

How does

fasterize()
do on a large set of polygons? Here I download the IUCN shapefile for the ranges of all terrestrial mammals and generate a 1/6 degree world map of mammalian biodiversity by rasterizing all the layers.
if(!dir.exists("Mammals_Terrestrial")) {
  download.file(
    "https://s3.amazonaws.com/hp3-shapefiles/Mammals_Terrestrial.zip",
    destfile = "Mammals_Terrestrial.zip") # 
mammal_shapes 
#> Reading layer `Mammals_Terrestrial' from data source `/Users/noamross/dropbox-eha/projects-eha/fasterize/Mammals_Terrestrial' using driver `ESRI Shapefile'
#> Simple feature collection with 42714 features and 27 fields
#> geometry type:  MULTIPOLYGON
#> dimension:      XY
#> bbox:           xmin: -180 ymin: -85.58276 xmax: 180 ymax: 89.99999
#> epsg (SRID):    4326
#> proj4string:    +proj=longlat +datum=WGS84 +no_defs
mammal_raster 
#> Unit: seconds
#>     expr   min    lq  mean median    uq   max neval
#>  mammals 0.847 0.857 0.883  0.886 0.894 0.963    20
par(mar=c(0,0.5,0,0.5))
plot(mammal_raster, axes=FALSE, box=FALSE)

About

fasterize is developed openly at EcoHealth Alliance under the USAID PREDICT project. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

https://www.ecohealthalliance.org/ https://ohi.vetmed.ucdavis.edu/programs-projects/predict-project

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.