All Projects β†’ ecohealthalliance β†’ Fasterize

ecohealthalliance / Fasterize

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

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to Fasterize

belg
Boltzmann entropy of a landscape gradient
Stars: ✭ 14 (-90.41%)
Mutual labels:  raster, spatial
GeoArrays.jl
Simple geographical raster interaction built on top of ArchGDAL, GDAL and CoordinateTransformations
Stars: ✭ 42 (-71.23%)
Mutual labels:  raster, spatial
Googleway
R Package for accessing and plotting Google Maps
Stars: ✭ 187 (+28.08%)
Mutual labels:  spatial, rstats
Wellknown
WKT <-> GeoJSON
Stars: ✭ 15 (-89.73%)
Mutual labels:  spatial, rstats
Stplanr
Sustainable transport planning with R
Stars: ✭ 352 (+141.1%)
Mutual labels:  spatial, rstats
NLMR
πŸ“¦ R package to simulate neutral landscape models πŸ”
Stars: ✭ 57 (-60.96%)
Mutual labels:  spatial, rstats
Landscapemetrics
Landscape Metrics for Categorical Map Patterns πŸ—ΊοΈ in R
Stars: ✭ 151 (+3.42%)
Mutual labels:  raster, spatial
spDataLarge
R package with large datasets for spatial analysis
Stars: ✭ 19 (-86.99%)
Mutual labels:  raster, spatial
Stars
Spatiotemporal Arrays, Raster and Vector Data Cubes
Stars: ✭ 363 (+148.63%)
Mutual labels:  raster, spatial
Prioritizr
Systematic conservation prioritization in R
Stars: ✭ 62 (-57.53%)
Mutual labels:  spatial, rstats
D3r
d3.js helpers for R
Stars: ✭ 133 (-8.9%)
Mutual labels:  rstats
Gganimate
A Grammar of Animated Graphics
Stars: ✭ 1,744 (+1094.52%)
Mutual labels:  rstats
Streamgraph
〰️ htmlwidget for creating streamgraph visualizations in R
Stars: ✭ 137 (-6.16%)
Mutual labels:  rstats
Colourpicker
🎨 A colour picker tool for Shiny and for selecting colours in plots (in R)
Stars: ✭ 144 (-1.37%)
Mutual labels:  rstats
Rstudiothemes
A curated list of RStudio themes found on Github
Stars: ✭ 134 (-8.22%)
Mutual labels:  rstats
Openlayers Editor
OpenLayers Editor
Stars: ✭ 138 (-5.48%)
Mutual labels:  spatial
Shinyfiles
A shiny extension for server side file access
Stars: ✭ 133 (-8.9%)
Mutual labels:  rstats
Rsuite
The most complete R development and data science platform.
Stars: ✭ 133 (-8.9%)
Mutual labels:  rstats
Geojsonio
Convert many data formats to & from GeoJSON & TopoJSON
Stars: ✭ 132 (-9.59%)
Mutual labels:  rstats
Googlelanguager
R client for the Google Translation API, Google Cloud Natural Language API and Google Cloud Speech API
Stars: ✭ 145 (-0.68%)
Mutual labels:  rstats

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 <- rbind(c(-180,-20), c(-140,55), c(10, 0), c(-140,-60), c(-180,-20))
hole <- rbind(c(-150,-20), c(-100,-10), c(-110,20), c(-150,-20))
p1 <- list(p1, hole)
p2 <- list(rbind(c(-10,0), c(140,60), c(160,0), c(140,-55), c(-10,0)))
p3 <- list(rbind(c(-125,0), c(0,60), c(40,5), c(15,-45), c(-125,0)))
pols <- st_sf(value = c(1,2,3),
             geometry = st_sfc(lapply(list(p1, p2, p3), st_polygon)))
r <- raster(pols, res = 1)
r <- fasterize(pols, r, field = "value", fun="sum")
plot(r)

Performance

Let's compare fasterize() to raster::rasterize():

pols_r <- as(pols, "Spatial")
bench <- microbenchmark::microbenchmark(
  rasterize = r <- raster::rasterize(pols_r, r, field = "value", fun="sum"),
  fasterize = f <- fasterize(pols, r, field = "value", fun="sum"),
  unit = "ms"
)
print(bench, digits = 3)
#> 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") # <-- 383 MB
  unzip("Mammals_Terrestrial.zip", exdir = ".")
  unlink("Mammals_Terrestrial.zip")
}
mammal_shapes <- st_read("Mammals_Terrestrial")
#> 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 <- raster(mammal_shapes, res = 1/6)
bench2 <- microbenchmark::microbenchmark(
  mammals = mammal_raster <- fasterize(mammal_shapes, mammal_raster, fun="sum"),
  times=20, unit = "s")
print(bench2, digits=3)
#> 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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].