-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathREADME.qmd
More file actions
164 lines (126 loc) · 4.61 KB
/
Copy pathREADME.qmd
File metadata and controls
164 lines (126 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
---
format: gfm
default-image-extension: ''
knitr:
opts_chunk:
collapse: true
comment: "#>"
warning: false
message: false
dpi: 150
fig.path: "man/figures/README-"
tidy: "styler"
dev: "ragg_png"
out.width: "100%"
---
<!-- README.md is generated from README.qmd. Please edit that file -->
# rasterpic <a href="https://dieghernan.github.io/rasterpic/"><img src="man/figures/logo.png" alt="rasterpic website" align="right" height="139"/></a>
<!-- badges: start -->
[](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://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/#inactive)
[](https://CRAN.R-project.org/package=rasterpic)
<!-- badges: end -->
**rasterpic** is a tiny package with a single goal: geotag an image and return a
**terra** `SpatRaster` object using coordinates from supported spatial input
classes (see `?terra::SpatRaster`).
::: callout-note
This package is stable and maintained on a best-effort basis. I currently
prioritize CRAN compatibility, bug fixes and regressions over new features.
:::
## Installation
::: pkgdown-release
Install **rasterpic** from
[**CRAN**](https://CRAN.R-project.org/package=rasterpic):
```{r}
#| eval: false
install.packages("rasterpic")
```
:::
::: pkgdown-devel
Check the documentation for the development version at
<https://dieghernan.github.io/rasterpic/dev/>.
You can install the development version of **rasterpic** with:
```{r}
#| eval: false
# install.packages("pak")
pak::pak("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
`rasterpic_img()` can geotag an image from several spatial input classes:
- **sf** classes: `sf`, `sfc`, `sfg` and `bbox`.
- **terra** classes: `SpatRaster`, `SpatVector` and `SpatExtent`.
- **stars** class: `stars`.
- A numeric coordinate vector of the form `c(xmin, ymin, xmax, ymax)`.
`rasterpic_img()` is an S3 generic. Methods for extent-like inputs use the
object extent, and vector methods can also mask the image to the object shape.
This example uses an `sf` object:
```{r}
#| label: example-basic
#| fig-cap: Example using **rasterpic** with the UK flag.
library(rasterpic)
library(sf)
library(terra)
# Use 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)
# Geotag the image.
uk_flag <- rasterpic_img(uk, img)
uk_flag
# Plot with ggplot2 and tidyterra.
library(tidyterra)
library(ggplot2)
autoplot(uk_flag) +
geom_sf(data = uk, color = alpha("blue", 0.5))
```
You can also adjust the expansion, alignment, cropping and masking options:
```{r}
#| label: align-crop-mask
#| fig-cap: Example using **rasterpic** with the UK flag cropped to the shape.
# Align, crop and mask the image.
uk_flag2 <- rasterpic_img(uk, img, halign = 0.2, crop = TRUE, mask = TRUE)
autoplot(uk_flag2) +
geom_sf(data = uk, fill = NA)
```
## Supported image formats
**rasterpic** can read the following image formats:
- `png` files.
- `jpeg`/`jpg` files.
- `tiff`/`tif` 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"))
```