An open API service indexing awesome lists of open source software.

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

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

[![CRAN
status](https://www.r-pkg.org/badges/version/rasterpic)](https://CRAN.R-project.org/package=rasterpic)
[![CRAN
results](https://badges.cranchecks.info/worst/rasterpic.svg)](https://cran.r-project.org/web/checks/check_results_rasterpic.html)
[![R-CMD-check](https://github.com/dieghernan/rasterpic/actions/workflows/check-full.yaml/badge.svg)](https://github.com/dieghernan/rasterpic/actions/workflows/check-full.yaml)
[![R-hub](https://github.com/dieghernan/rasterpic/actions/workflows/rhub.yaml/badge.svg)](https://github.com/dieghernan/rasterpic/actions/workflows/rhub.yaml)
[![codecov](https://codecov.io/gh/dieghernan/rasterpic/branch/main/graph/badge.svg?token=jSZ4RIsj91)](https://app.codecov.io/gh/dieghernan/rasterpic)
[![r-universe](https://dieghernan.r-universe.dev/badges/rasterpic)](https://dieghernan.r-universe.dev/rasterpic)
[![CodeFactor](https://www.codefactor.io/repository/github/dieghernan/rasterpic/badge)](https://www.codefactor.io/repository/github/dieghernan/rasterpic)
[![DOI](https://img.shields.io/badge/DOI-10.32614/CRAN.package.rasterpic-blue)](https://doi.org/10.32614/CRAN.package.rasterpic)
[![Project Status: Active -- The project has reached a stable, usable state and
is being actively
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![status](https://tinyverse.netlify.app/status/rasterpic)](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





dieghernan

### Issues





rhijmans