{"id":18722648,"url":"https://github.com/mdsumner/discretize","last_synced_at":"2025-11-11T05:30:22.392Z","repository":{"id":72211333,"uuid":"261712737","full_name":"mdsumner/discretize","owner":"mdsumner","description":"scanline adventures, see hypertidy/controlledburn for this done properly","archived":false,"fork":false,"pushed_at":"2022-11-29T22:44:14.000Z","size":57,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-28T12:17:13.120Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"R","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/mdsumner.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"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":null}},"created_at":"2020-05-06T09:32:10.000Z","updated_at":"2023-02-10T23:48:17.000Z","dependencies_parsed_at":"2024-01-15T09:30:39.597Z","dependency_job_id":null,"html_url":"https://github.com/mdsumner/discretize","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdsumner%2Fdiscretize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdsumner%2Fdiscretize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdsumner%2Fdiscretize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdsumner%2Fdiscretize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mdsumner","download_url":"https://codeload.github.com/mdsumner/discretize/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239587244,"owners_count":19663892,"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":[],"created_at":"2024-11-07T13:42:20.446Z","updated_at":"2025-11-11T05:30:22.350Z","avatar_url":"https://github.com/mdsumner.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\r\noutput: github_document\r\neditor_options: \r\n  chunk_output_type: console\r\n---\r\n\r\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\r\n\r\n```{r, include = FALSE}\r\nknitr::opts_chunk$set(\r\n  collapse = TRUE,\r\n  comment = \"#\u003e\",\r\n  fig.path = \"man/figures/README-\",\r\n  out.width = \"100%\"\r\n)\r\n```\r\n\r\n# dicretize\r\n\r\n\u003c!-- badges: start --\u003e\r\n\u003c!-- badges: end --\u003e\r\n\r\nThe goal of dicretize is to rasterize polygons as purely as possible, and return\r\nthe sparsest imaginable storage of a polygon raster. A rasterized polygon\r\nconsists of eminently compressable *run lengths* of scan lines, but it's not\r\nmuch use if we've instantiated the massive matrix just to store those scan lines. \r\n\r\nWIP\r\n\r\n- [ ] make it work!\r\n- [ ] remove all trace of raster package\r\n- [ ] return run-length start / stop scan lines of polygon ID\r\n- [ ] convert to a real programming language, or speed up the R code\r\n\r\n\r\n## Installation\r\n\r\ndon't do this, life is pain use 'stars::st_rasterize'\r\n\r\nYou can install the development version from [GitHub](https://github.com/mdsumner/discretize) with:\r\n\r\n``` r\r\n# install.packages(\"devtools\")\r\ndevtools::install_github(\"mdsumner/discretize\")\r\n```\r\n## Example\r\n\r\nThis is a basic example which shows how badly this is working. \r\n\r\n```{r example}\r\nlibrary(dicretize)\r\ndiscretize(silicate::minimal_mesh, 150, 180)\r\n```\r\n\r\nHow small could we store this? Well there's 304 fill bands, and let's take the \r\nworst case visually above we'd need 3 sets of polygon run lengths per line, so w'd \r\nneed 150 * 3 * (2 + 1). 150 rows (worst case), 3 regions (worst case, occurs in part\r\nof this figure), and 2 + 1 values each (start, run-length, polygon ID) and we have\r\na massive 1350 values to store. As a raster, we have to store 150 * 180 (27000) values, \r\nand even if we drop the white regions it's not much saving. This really bites when you\r\nwant a 5-10m raster of a region like Tasmania, and the grid is 12Gb of wasted pixels\r\nin memory, it just doesn't work. (Yes you can use GDAL to work out of memory, but\r\nthis is just a great idea and is really neat so stay right away). \r\n\r\n\r\nDoes this really not work? It's not too bad, there's bugs though. \r\n\r\n```{r polygons}\r\npar(mar = rep(0, 4), xaxs = \"i\", yaxs = \"i\", bg = \"aliceblue\")\r\nsystem.time(discretize(silicate::inlandwaters, 720, 780))\r\n```\r\n\r\n---\r\n\r\n## Code of Conduct\r\n\r\nPlease note that the dicretize project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.\r\n\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdsumner%2Fdiscretize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmdsumner%2Fdiscretize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdsumner%2Fdiscretize/lists"}