{"id":18520147,"url":"https://github.com/mlr-org/mlr3spatial","last_synced_at":"2025-10-28T07:31:08.717Z","repository":{"id":38106618,"uuid":"233107318","full_name":"mlr-org/mlr3spatial","owner":"mlr-org","description":"Spatial objects within the mlr3 ecosystem","archived":false,"fork":false,"pushed_at":"2024-08-14T09:40:17.000Z","size":11547,"stargazers_count":43,"open_issues_count":4,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-05T20:30:08.888Z","etag":null,"topics":["mlr3","r","r-package","raster-prediction","spatial","spatial-modelling"],"latest_commit_sha":null,"homepage":"https://mlr3spatial.mlr-org.com","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mlr-org.png","metadata":{"funding":{"github":"mlr-org"},"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-10T18:28:34.000Z","updated_at":"2024-11-15T12:54:49.000Z","dependencies_parsed_at":"2024-12-16T21:10:26.425Z","dependency_job_id":"e9524038-1d19-4b55-8687-de077f6bd622","html_url":"https://github.com/mlr-org/mlr3spatial","commit_stats":{"total_commits":226,"total_committers":6,"mean_commits":"37.666666666666664","dds":0.5707964601769911,"last_synced_commit":"b0133063a8d1ad7d947a2b66576da629412665be"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlr-org%2Fmlr3spatial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlr-org%2Fmlr3spatial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlr-org%2Fmlr3spatial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlr-org%2Fmlr3spatial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlr-org","download_url":"https://codeload.github.com/mlr-org/mlr3spatial/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238610572,"owners_count":19500675,"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":["mlr3","r","r-package","raster-prediction","spatial","spatial-modelling"],"created_at":"2024-11-06T17:18:48.143Z","updated_at":"2025-10-28T07:31:08.710Z","avatar_url":"https://github.com/mlr-org.png","language":"HTML","funding_links":["https://github.com/sponsors/mlr-org"],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n```{r, include=FALSE}\nlibrary(mlr3)\nlibrary(mlr3spatial)\nlibrary(terra, exclude = \"resample\")\nlibrary(sf)\n\nlgr::get_logger(\"mlr3\")$set_threshold(\"warn\")\nlgr::get_logger(\"mlr3spatial\")$set_threshold(\"warn\")\nset.seed(1)\noptions(\n    datatable.print.nrows = 10,\n    datatable.print.class = FALSE,\n    datatable.print.keys = FALSE,\n    width = 100)\n```\n\n# mlr3spatial \u003cimg src=\"man/figures/logo.png\" align=\"right\" width = \"120\" /\u003e\n\nPackage website: [release](https://mlr3spatial.mlr-org.com/) | [dev](https://mlr3spatial.mlr-org.com/dev/)\n\n\u003c!-- badges: start --\u003e\n[![r-cmd-check](https://github.com/mlr-org/mlr3spatial/actions/workflows/r-cmd-check.yml/badge.svg)](https://github.com/mlr-org/mlr3spatial/actions/workflows/r-cmd-check.yml)\n[![CRAN status](https://www.r-pkg.org/badges/version/mlr3spatial)](https://CRAN.R-project.org/package=mlr3spatial)\n[![Mattermost](https://img.shields.io/badge/chat-mattermost-orange.svg)](https://lmmisld-lmu-stats-slds.srv.mwn.de/mlr_invite/)\n\u003c!-- badges: end --\u003e\n\n*mlr3spatial* is the package for spatial objects within the [`mlr3`](https://mlr-org.com) ecosystem.\nThe package directly loads data from [`sf`](https://CRAN.R-project.org/package=sf) objects to train any mlr3 learner.\nThe learner can predict on various raster formats ([`terra`](https://CRAN.R-project.org/package=terra), [`raster`](https://CRAN.R-project.org/package=raster) and [`stars`](https://CRAN.R-project.org/package=stars)) and writes the prediction raster to disk.\nmlr3spatial reads large raster objects in chunks to avoid memory issues and predicts the chunks in parallel.\nCheck out [`mlr3spatiotempcv`](https://github.com/mlr-org/mlr3spatiotempcv) for spatiotemporal resampling within mlr3.\n\n## Resources\n\nThere are sections about spatial data in the [mlr3book](https://mlr3book.mlr-org.com).\n\n* Learn how to [predict](https://mlr3book.mlr-org.com/chapters/chapter13/beyond_regression_and_classification.html#sec-spatial-prediction) a spatial raster image.\n* Estimate the performance of a model with [spatial cross-validation](https://mlr3book.mlr-org.com/chapters/chapter13/beyond_regression_and_classification.html#sec-spatiotemporal).\n\nThe gallery features articles about spatial data in the mlr3 ecosystem.\n\n* Learn the basics with a [land cover classification](https://mlr-org.com/gallery/technical/2023-02-27-land-cover-classification/) of the city of Leipzig.\n\n## Installation\n\nInstall the last release from CRAN:\n\n```{r, eval=FALSE}\ninstall.packages(\"mlr3spatial\")\n```\n\nInstall the development version from GitHub:\n\n```{r, eval=FALSE}\nremotes::install_github(\"mlr-org/mlr3spatial\")\n```\n\n## Example\n\nOur goal is to map the land cover of the city of Leipzig.\nThe `mlr3spatial` package contains a Sentinel-2 scene of the city of Leipzig and a point vector with training sites.\nThe Sentinel-2 scene is a 10m resolution multispectral image with 7 bands and the NDVI.\nThe points represent samples of the four land cover classes: Forest, Pastures, Urban and Water.\nWe load the raster with the [`terra`](https://CRAN.R-project.org/package=terra) package and the vector with the [`sf`](https://CRAN.R-project.org/package=sf) package in the R Session.\n\n```{r}\nlibrary(mlr3verse)\nlibrary(mlr3spatial)\nlibrary(terra, exclude = \"resample\")\nlibrary(sf)\n\nleipzig = read_sf(system.file(\"extdata\", \"leipzig_points.gpkg\", package = \"mlr3spatial\"), stringsAsFactors = TRUE)\n\nleipzig_raster = rast(system.file(\"extdata\", \"leipzig_raster.tif\", package = \"mlr3spatial\"))\n```\n\nThe function `as_task_classif_st()` converts the `sf::sf` object to a spatial classification task.\n\n```{r}\ntask = as_task_classif_st(leipzig, target = \"land_cover\")\ntask\n```\n\nThe points are located in the district of Lindenau and Zentrum-West.\n\n\u003cimg src=\"man/figures/sentinel.png\" /\u003e\n\nNow we train a classification tree on the leipzig task.\n\n```{r}\nlearner = lrn(\"classif.rpart\")\nlearner$train(task)\n```\n\nAs a last step, we predict the land cover class for the whole area of interest.\nFor this, we pass the Sentinel-2 scene and the trained learner to the `predict_spatial()` function.\n\n```{r}\nland_cover = predict_spatial(leipzig_raster, learner)\n```\n\n\u003cimg src=\"man/figures/land_cover.png\" /\u003e\n\n## FAQ\n\n\u003cdetails\u003e\n  \u003csummary\u003eWill mlr3spatial support spatial learners?\u003c/summary\u003e\n  \u003cbr\u003e\n Eventually. It is not yet clear whether these would live in mlr3extralearners or in mlr3spatial.\n So far there are none yet.\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eWhy are there two packages, mlr3spatial and mlr3spatiotempcv?\u003c/summary\u003e\n  \u003cbr\u003e\n  mlr3spatiotempcv is solely devoted to resampling techniques.\n  There are quite a few and keeping packages small is one of the development philosophies of the mlr3 framework.\n  Also back in the days when mlr3spatiotempcv was developed, it was not yet clear how we want to structure additional spatial components such as prediction support for spatial classes and so on.\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlr-org%2Fmlr3spatial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlr-org%2Fmlr3spatial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlr-org%2Fmlr3spatial/lists"}