{"id":26120544,"url":"https://github.com/hypertidy/fasterize","last_synced_at":"2025-04-07T17:07:40.871Z","repository":{"id":18516016,"uuid":"84496110","full_name":"hypertidy/fasterize","owner":"hypertidy","description":"High performance raster conversion for modern spatial data 🚀🌏▦","archived":false,"fork":false,"pushed_at":"2025-03-08T21:14:18.000Z","size":1131,"stargazers_count":181,"open_issues_count":28,"forks_count":15,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-03-31T16:13:53.545Z","etag":null,"topics":["r","raster","rcpp","rcpparmadillo","rstats","sf","spatial"],"latest_commit_sha":null,"homepage":"https://hypertidy.github.io/fasterize/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hypertidy.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":"codemeta.json"}},"created_at":"2017-03-09T22:50:54.000Z","updated_at":"2025-03-22T08:14:41.000Z","dependencies_parsed_at":"2023-12-16T17:38:43.673Z","dependency_job_id":"7684e0b6-91a0-4353-abf5-9c544557dd46","html_url":"https://github.com/hypertidy/fasterize","commit_stats":{"total_commits":98,"total_committers":7,"mean_commits":14.0,"dds":0.6734693877551021,"last_synced_commit":"2955e39e40cbd08837e633c3d82ffd679e73ea62"},"previous_names":["hypertidy/fasterize"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypertidy%2Ffasterize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypertidy%2Ffasterize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypertidy%2Ffasterize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypertidy%2Ffasterize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hypertidy","download_url":"https://codeload.github.com/hypertidy/fasterize/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247694875,"owners_count":20980733,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["r","raster","rcpp","rcpparmadillo","rstats","sf","spatial"],"created_at":"2025-03-10T13:26:28.625Z","updated_at":"2025-04-07T17:07:40.841Z","avatar_url":"https://github.com/hypertidy.png","language":"C++","readme":"---\noutput: \n  github_document:\n    html_preview: FALSE\n---\n\n```{r, setup, echo = FALSE, message = FALSE}\nknitr::opts_chunk$set(\n  comment = \"#\u003e\",\n  tidy = FALSE,\n  error = FALSE,\n  fig.width = 7,\n  fig.height = 4.5,\n  fig.path = 'vignettes/readme-',\n  cache=FALSE)\n```\n\n\n\n# fasterize\n\nFast polygon-to-raster conversion, burn polygon shapes and/or values into pixels. \n\n\n\n\u003c!-- badges: start --\u003e\n  [![R-CMD-check](https://github.com/hypertidy/fasterize/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/hypertidy/fasterize/actions/workflows/R-CMD-check.yaml)\n  [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)\n[![MIT Licensed - Copyright 2016 EcoHealth Alliance](https://img.shields.io/badge/license-MIT-blue.svg)](https://badges.mit-license.org/)\n[![CRAN status](https://www.r-pkg.org/badges/version/fasterize)](https://CRAN.R-project.org/package=fasterize)\n[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/fasterize)](https://www.r-pkg.org/pkg/fasterize)\n[![Codecov test coverage](https://codecov.io/gh/hypertidy/fasterize/graph/badge.svg)](https://app.codecov.io/gh/hypertidy/fasterize)\n\u003c!-- badges: end --\u003e\n  \n\n**fasterize** is a high-performance replacement for the `rasterize()` function\nin the [**raster**](https://cran.r-project.org/package=raster) package.\n\nFunctionality is currently limited to rasterizing polygons in [**sf**](https://cran.r-project.org/package=sf)-type\ndata frames.\n\n## Installation\n\nInstall the current version of **fasterize** from CRAN:\n\n```{r eval = FALSE}\ninstall.packages('fasterize')\n```\n\nInstall the development version of **fasterize** with [**devtools**](https://cran.r-project.org/package=devtools):\n\n```{r eval = FALSE}\ndevtools::install_github(\"hypertidy/fasterize\")\n```\n\n**fasterize** uses [**Rcpp**](https://cran.r-project.org/package=Rcpp) and thus requires a compile toolchain to install from source.\nTesting (and for normal use of sf objects) requires [**sf**](https://cran.r-project.org/package=sf), which requires GDAL, GEOS, and PROJ to be installed.\n\n## Usage\n\nThe main function, `fasterize()`, takes the same inputs as `raster::rasterize()` but currently has fewer options and is \nis limited to rasterizing polygons.\n\nA `raster()` and `plot()` methods for rasters are re-exported from the [raster package](https://cran.r-project.org/package=raster).\n\n\n```{r example-1, message=FALSE}\nlibrary(raster)\nlibrary(fasterize)\nlibrary(wk)\nlibrary(fasterize)\np123 \u003c- c(paste0(\"POLYGON ((-180 -20, -140 55, 10 0, -140 -60, -180 -20),\", \n                  \"(-150 -20, -100 -10, -110 20, -150 -20))\"), \n             \"POLYGON ((-10 0, 140 60, 160 0, 140 -55, -10 0))\", \n             \"POLYGON ((-125 0, 0 60, 40 5, 15 -45, -125 0))\")\npols \u003c- data.frame(value = seq_along(p123), geometry = wk::as_wkt(p123))\nex \u003c- as.numeric(wk_bbox(pols))[c(1, 3, 2, 4)]\nr \u003c- raster::raster(raster::extent(ex), res = 1)\nr \u003c- fasterize(pols, r, field = \"value\", fun=\"sum\")\nplot(r)\n```\n\n## Performance\n\nLet's compare `fasterize()` to  `terra::rasterize()`:\n\n```{r benchmark, cache=TRUE}\npols_t \u003c- terra::vect(p123)\npols_t$value \u003c- 1:3\n#pols_r \u003c-  as(pols_t, \"Spatial\")\ntr \u003c- terra::rast(r)\n\nbench \u003c- microbenchmark::microbenchmark(\n # rasterize = r \u003c- raster::rasterize(pols_r, r, field = \"value\", fun=\"sum\"),\n  terrarize = tr \u003c- terra::rasterize(pols_t, tr, field = \"value\", fun = \"sum\"),\n  fasterize = f \u003c- fasterize(pols, r, field = \"value\", fun=\"sum\"),\n  unit = \"ms\"\n)\n\nprint(bench, digits = 3)\n```\n\n\n\nHow does `fasterize()` do on a large set of polygons? Here I download the IUCN shapefile for the ranges of all terrestrial mammals and generate\na 1/6 degree world map of mammalian biodiversity by rasterizing all the layers.\n\n\n(this doesn't work anymore because the source data is gone, left as a record 2024-09-25). \n\n```{r download, eval=FALSE, cache=TRUE}\nif(!dir.exists(\"Mammals_Terrestrial\")) {\n  download.file(\n    \"https://s3.amazonaws.com/hp3-shapefiles/Mammals_Terrestrial.zip\",\n    destfile = \"Mammals_Terrestrial.zip\") # \u003c-- 383 MB\n  unzip(\"Mammals_Terrestrial.zip\", exdir = \".\")\n  unlink(\"Mammals_Terrestrial.zip\")\n}\n\n```\n\n```{r so-damn-fast, cache=FALSE, eval=FALSE}\nmammal_shapes \u003c- st_read(\"Mammals_Terrestrial\")\nmammal_raster \u003c- raster(mammal_shapes, res = 1/6)\nbench2 \u003c- microbenchmark::microbenchmark(\n  mammals = mammal_raster \u003c- fasterize(mammal_shapes, mammal_raster, fun=\"sum\"),\n  times=20, unit = \"s\")\nprint(bench2, digits=3)\npar(mar=c(0,0.5,0,0.5))\nplot(mammal_raster, axes=FALSE, box=FALSE)\n```\n\n\n    #\u003e Unit: seconds\n    #\u003e     expr   min    lq  mean median    uq   max neval\n    #\u003e  mammals 0.847 0.857 0.883  0.886 0.894 0.963    20\n\n\n\n![](vignettes/readme-so-damn-fast-1.png)\n\n\n## About\n\n**fasterize** was developed openly at [EcoHealth Alliance](https://www.ecohealthalliance.org/) under the USAID PREDICT project by Noam Ross.   The repository for hosting fasterize was taken over by  Michael Sumner in December 2022, and was later migrated from Github 'ecohealthalliance/fasterize' to https://github.com/hypertidy/fasterize in March 2025. \n\n\nPlease note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.\n\n[![https://www.ecohealthalliance.org/](vignettes/eha-footer.png)](https://www.ecohealthalliance.org/)\n[![https://ohi.vetmed.ucdavis.edu/programs-projects/predict-project](vignettes/predictfooter.png)](https://ohi.vetmed.ucdavis.edu/programs-projects/predict-project)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypertidy%2Ffasterize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhypertidy%2Ffasterize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypertidy%2Ffasterize/lists"}