Skip to content

Commit

Permalink
Layers are named sequentally
Browse files Browse the repository at this point in the history
  • Loading branch information
dieghernan committed Feb 5, 2025
1 parent 27dc1bc commit 1222dd5
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 75 deletions.
58 changes: 0 additions & 58 deletions .github/workflows/update-citation-cff.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ message: 'To cite package "rasterpic" in publications use:'
type: software
license: MIT
title: 'rasterpic: Convert Digital Images into ''SpatRaster'' Objects'
version: 0.2.6
version: 0.2.6.9000
doi: 10.32614/CRAN.package.rasterpic
identifiers:
- type: doi
Expand All @@ -30,7 +30,7 @@ preferred-citation:
orcid: https://orcid.org/0000-0001-8457-4658
doi: 10.32614/CRAN.package.rasterpic
year: '2025'
version: 0.2.6
version: 0.2.6.9000
url: https://dieghernan.github.io/rasterpic/
abstract: Generate SpatRaster objects, as defined by the terra package, from digital
images, using a specified spatial object as a geographical reference.
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rasterpic
Title: Convert Digital Images into 'SpatRaster' Objects
Version: 0.2.6
Version: 0.2.6.9000
Authors@R:
person("Diego", "Hernangómez", , "[email protected]", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0001-8457-4658"))
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# rasterpic (development version)

- When the output has 3 or more layers, the first three are renamed as
`"r", "g", "b"`. In cases with 4 layers or more the fourth layer is renames
as `"alpha"`. This allows compatibility with **tmap** `>= 4.0` avoiding
error `! [subset] you cannot select a layer with a name that is not unique`.

# rasterpic 0.2.6

- Update documentation.
Expand Down
8 changes: 8 additions & 0 deletions R/rasterpic_img.R
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,15 @@ rasterpic_img <- function(x, img, halign = .5, valign = .5, expand = 0,
if (!terra::has.RGB(new_rast)) {
terra::RGB(new_rast) <- c(1, 2, 3)
}

# Rename RGB channels
nms <- names(new_rast)
nms[c(1, 2, 3)] <- c("r", "g", "b")

if (length(nms) >= 4) nms[4] <- "alpha"
names(new_rast) <- nms
}


return(new_rast)
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ uk_flag
#> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857)
#> source(s) : memory
#> colors RGB : 1, 2, 3
#> names : lyr.1, lyr.2, lyr.3
#> min values : 0, 14, 35
#> max values : 255, 255, 255
#> names : r, g, b
#> min values : 0, 14, 35
#> max values : 255, 255, 255

# Plot it!
# Using ggplot2 + tidyterra
Expand Down Expand Up @@ -142,7 +142,7 @@ A BibTeX entry for LaTeX users is:
doi = {10.32614/CRAN.package.rasterpic},
author = {Diego Hernangómez},
year = {2025},
version = {0.2.6},
version = {0.2.6.9000},
url = {https://dieghernan.github.io/rasterpic/},
abstract = {Generate SpatRaster objects, as defined by the terra package, from digital images, using a specified spatial object as a geographical reference.},
}
Expand Down
6 changes: 3 additions & 3 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
"codeRepository": "https://github.com/dieghernan/rasterpic",
"issueTracker": "https://github.com/dieghernan/rasterpic/issues",
"license": "https://spdx.org/licenses/MIT",
"version": "0.2.6",
"version": "0.2.6.9000",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
"url": "https://r-project.org"
},
"runtimePlatform": "R version 4.4.2 (2024-10-31 ucrt)",
"runtimePlatform": "R version 4.4.2 (2024-10-31)",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
Expand Down Expand Up @@ -160,7 +160,7 @@
"SystemRequirements": null
},
"keywords": ["cran", "jpeg", "jpg", "maps", "png", "r", "r-package", "r-stats", "raster", "rstats", "sf", "terra", "tif", "tiff", "cran-r"],
"fileSize": "1156.638KB",
"fileSize": "1157.549KB",
"citation": [
{
"@type": "SoftwareSourceCode",
Expand Down
4 changes: 2 additions & 2 deletions inst/schemaorg.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"runtimePlatform": "R version 4.4.2 (2024-10-31 ucrt)",
"version": "0.2.6"
"runtimePlatform": "R version 4.4.2 (2024-10-31)",
"version": "0.2.6.9000"
},
{
"id": "https://doi.org/10.32614/CRAN.package.rasterpic",
Expand Down
Binary file modified man/figures/README-align-crop-mask-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-example-basic-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tests/testthat/test-fileformat.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ test_that("Test transparent", {
)

raster <- rasterpic_img(x, img)

expect_identical(names(raster), c("r", "g", "b", "alpha"))

expect_true(terra::has.RGB(raster))

png_dim <- png::readPNG(img)
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-nlayers.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ test_that("Check how it works with 2 layer file", {
)

r <- rasterpic_img(x, img)
expect_identical(names(r), c("r", "g", "b"))

# Write as geotiff with 2 layers

Expand Down
10 changes: 5 additions & 5 deletions vignettes/articles/plots.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ with several packages.
The most straightforward option is to use the base `plot()` methods provided by
the package **terra** (`terra::plotRGB()`):

```{r setup}
```{r setup, fig.alt="Example: plot with terra package"}
library(rasterpic)
library(terra)
Expand All @@ -46,7 +46,7 @@ plotRGB(uk_img)

**tidyterra** provides full support for **terra** `SpatRaster` objects:

```{r}
```{r tterra, fig.alt="Example: plot with tidyterra package"}
library(ggplot2)
library(tidyterra)
Expand All @@ -58,7 +58,7 @@ ggplot() +

**tmap** can be also used to create great maps:

```{r}
```{r tmap, fig.alt="Example: plot with tmap package"}
library(tmap)
tm_shape(uk_img) +
Expand All @@ -70,7 +70,7 @@ tm_shape(uk_img) +

**mapsf** also provides this functionality:

```{r}
```{r mapsf, fig.alt="Example: plot with mapsf package"}
library(mapsf)
mf_raster(uk_img)
Expand All @@ -86,7 +86,7 @@ mf_inset_off()
map tiles from different providers. It also has a specific function for plotting
**terra** `SpatRaster` objects:

```{r}
```{r maptiles, fig.alt="Example: plot with maptiles package"}
library(maptiles)
other_tile <- get_tiles(uk, crop = TRUE, zoom = 6)
Expand Down

0 comments on commit 1222dd5

Please sign in to comment.