https://github.com/dieghernan/rasterpic
Convert digital images into georeferenced rasters
https://github.com/dieghernan/rasterpic
cran cran-r jpeg jpg maps png r r-package r-stats raster rstats sf terra tif tiff
Last synced: 7 months ago
JSON representation
Convert digital images into georeferenced rasters
- Host: GitHub
- URL: https://github.com/dieghernan/rasterpic
- Owner: dieghernan
- License: other
- Created: 2022-01-24T07:30:40.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-11T21:38:05.000Z (7 months ago)
- Last Synced: 2025-03-11T22:27:43.264Z (7 months ago)
- Topics: cran, cran-r, jpeg, jpg, maps, png, r, r-package, r-stats, raster, rstats, sf, terra, tif, tiff
- Language: R
- Homepage: https://dieghernan.github.io/rasterpic/
- Size: 329 MB
- Stars: 12
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Citation: CITATION.cff
- Codemeta: codemeta.json
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
warning = FALSE,
message = FALSE,
tidy = "styler",
dev = "ragg_png",
fig.path = "man/figures/README-",
dpi = 150,
out.width = "100%"
)
```# rasterpic
[](https://CRAN.R-project.org/package=rasterpic)
[](https://cran.r-project.org/web/checks/check_results_rasterpic.html)
[](https://github.com/dieghernan/rasterpic/actions/workflows/check-full.yaml)
[](https://github.com/dieghernan/rasterpic/actions/workflows/rhub.yaml)
[](https://app.codecov.io/gh/dieghernan/rasterpic)
[](https://dieghernan.r-universe.dev/rasterpic)
[](https://www.codefactor.io/repository/github/dieghernan/rasterpic)
[](https://doi.org/10.32614/CRAN.package.rasterpic)
[](https://www.repostatus.org/#active)
[](https://CRAN.R-project.org/package=rasterpic)**rasterpic** is a tiny package with one single goal: to transform an image into
a `SpatRaster` object (see `?terra::SpatRaster`).## Installation
Install **rasterpic** from
[**CRAN**](https://CRAN.R-project.org/package=rasterpic):```{r, eval=FALSE}
install.packages("rasterpic")
```You can install the developing version of **rasterpic** with:
```{r, eval=FALSE}
remotes::install_github("dieghernan/rasterpic")
```Alternatively, you can install **rasterpic** using the
[r-universe](https://dieghernan.r-universe.dev/rasterpic):```{r, eval=FALSE}
# Install rasterpic in R:
install.packages("rasterpic",
repos = c(
"https://dieghernan.r-universe.dev",
"https://cloud.r-project.org"
)
)
```## Example
This package allows you to create cool maps by using a wide variety of objects:
- Spatial object created with the **sf** package: `sf`, `sfc`, `sfg` or
`bbox`.
- Spatial objects created with the **terra** package: `SpatRaster`,
`SpatVector`, `SpatExtent`.
- A vector of coordinates with the form `c(xmin, ymin, xmax, yman)`An example using an `sf` object:
```{r example-basic}
library(rasterpic)
library(sf)
library(terra)# The flag of the United Kingdom
img <- system.file("img/UK_flag.png", package = "rasterpic")
uk <- read_sf(system.file("gpkg/UK.gpkg", package = "rasterpic"))class(uk)
# Rasterize!
uk_flag <- rasterpic_img(uk, img)uk_flag
# Plot it!
# Using ggplot2 + tidyterra
library(tidyterra)
library(ggplot2)autoplot(uk_flag) +
geom_sf(data = uk, color = alpha("blue", 0.5))
```We can also play with other parameters, as well as modifying the alignment of
the image with respect to the object:```{r align-crop-mask}
# Align, crop and mask
uk_flag2 <- rasterpic_img(uk, img, halign = 0.2, crop = TRUE, mask = TRUE)autoplot(uk_flag2) +
geom_sf(data = uk, fill = NA)
```## Image formats admitted
**rasterpic** can parse the following image formats:
- `png` files.
- `jpg/jpeg` files.
- `tif/tiff` files.## Citation
```{r echo=FALSE, results='asis'}
print(citation("rasterpic"), style = "html")
```A BibTeX entry for LaTeX users is:
```{r echo=FALSE, comment=''}
toBibtex(citation("rasterpic"))
```## Contributors
All contributions to this project are gratefully acknowledged using the [`allcontributors` package](https://github.com/ropensci/allcontributors) following the [allcontributors](https://allcontributors.org) specification. Contributions of any kind are welcome!
### Code
### Issues