-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
80 lines (55 loc) · 2.77 KB
/
README.Rmd
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
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# ximage
<!-- badges: start -->
[![R-CMD-check](https://github.com/hypertidy/ximage/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/hypertidy/ximage/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
The goal of ximage is to make something like 'image()' and 'rasterImage()' but without the missing functionality and useability.
ximage supports making images from
- numeric, character, byte matrix
- numeric array
- nativeRaster
- list returned from `vapour::gdal_raster_()` functions which include numeric, character, byte vectors or nativeRaster
The orientation is in "raster-order", i.e. when you're looking at the picture it's topleft to topright, then scan lines down each row to the bottom (like western reading and `par(mfrow)` order). This matches the way that spatial data readers read imagery.
## Example
This is a basic example which shows you how to solve a common problem:
```{r example}
library(ximage)
ximage(topo) ## plot in the index space of the matrix
## or, plot in the geographic space (we happen to know this for this matrix)
ximage(topo, extent = c(-180, 180, -90, 90), axes = F)
axis(1); axis(2);box()
ximage(logo_a) ## plot a RGB array
## plot a native raster over the other in a different window
ximage(logo_n, extent = c(10, 20, 20, 40), add = TRUE)
ximage(topo, extent = c(40, 60, 80, 100), add = TRUE, col = hcl.colors(256))
```
We can get imagery from the internet, and plot it very quickly.
```{r imagery}
library(vapour) ## quite a recent version, dev in January 2024
virtual_earth <- "<GDAL_WMS><Service name=\"VirtualEarth\"><ServerUrl>http://a${server_num}.ortho.tiles.virtualearth.net/tiles/a${quadkey}.jpeg?g=90</ServerUrl></Service><MaxConnections>4</MaxConnections><Cache/></GDAL_WMS>"
par(mar = rep(0, 4))
px <- dev.size("px")
px[which.min(px)] <- 0
## change lon_0 and lat_0 to anywhere you like
im <- gdal_raster_nara(virtual_earth, target_ext = c(-1, 1, -1, 1) * 3e5, target_dim = px, target_crs = "+proj=laea +lon_0=147 +lat_0=-42")
system.time(ximage(im, asp = 1))
## crank up the size it's still fast
px <- px * 4
im <- gdal_raster_nara(virtual_earth, target_ext = c(-1, 1, -1, 1) * 3e5, target_dim = px, target_crs = "+proj=laea +lon_0=147 +lat_0=-42")
system.time(ximage(im, asp = 1))
```
## Code of Conduct
Please note that the ximage project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.