Giter VIP home page Giter VIP logo

rasterpic's Introduction

rasterpic

CRAN status CRAN results R-CMD-check R-hub codecov r-universe CodeFactor DOI Project Status: Active – The project has reached a stable, usable state and is being actively developed. status

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:

install.packages("rasterpic")

You can install the developing version of rasterpic with:

remotes::install_github("dieghernan/rasterpic")

Alternatively, you can install rasterpic using the r-universe:

# 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:

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)
#> [1] "sf"         "tbl_df"     "tbl"        "data.frame"

# Rasterize!
uk_flag <- rasterpic_img(uk, img)

uk_flag
#> class       : SpatRaster 
#> dimensions  : 400, 800, 3  (nrow, ncol, nlyr)
#> resolution  : 5398.319, 5398.319  (x, y)
#> extent      : -2542183, 1776472, 6430573, 8589900  (xmin, xmax, ymin, ymax)
#> 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

# 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:

# 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

Hernangómez D (2024). rasterpic: Convert Digital Images into SpatRaster Objects. doi:10.32614/CRAN.package.rasterpic, https://dieghernan.github.io/rasterpic/.

A BibTeX entry for LaTeX users is:

@Manual{R-rasterpic,
  title = {{rasterpic}: Convert Digital Images into {SpatRaster} Objects},
  doi = {10.32614/CRAN.package.rasterpic},
  author = {Diego Hernangómez},
  year = {2024},
  version = {0.2.5},
  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.},
}

rasterpic's People

Contributors

dependabot[bot] avatar dieghernan avatar github-actions[bot] avatar imgbot[bot] avatar imgbotapp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

imarcello

rasterpic's Issues

Release rasterpic 0.2.3

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Polish NEWS
  • urlchecker::url_check()
  • devtools::build_readme()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • git push

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version(push = TRUE)

test error

I see an error with this test in rasterpic:

 expect_error(
     rasterpic_img(x, img),
     "Cannot reach img on url http://this_is_an_error_url.fake"
 )
#Error: `rasterpic_img(x, img)` threw an error with unexpected message.
#Expected match: "Cannot reach img on url http://this_is_an_error_url.fake"
#Actual message: "'img' only accepts 'png', 'jpg' or 'jpeg' files"

Because (in rpic_read) , this does not throw an error:

img <- "http://this_is_an_error_url.fake"
tmp <- tempfile(fileext = paste0(".", tools::file_ext(img)))
download.file(img, tmp,  quiet = TRUE,  mode = "wb")
file.info(tmp)
#                     size isdir mode               mtime               ctime               atime exe
#file60b062b96d1.fake  385 FALSE  666 2023-08-31 17:37:04 2023-08-31 17:36:44 2023-08-31 17:37:04  no

This is on Windows with R 4.3.1

Release rasterpic 0.2.1

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • git push

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • git push
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • git push

Release rasterpic 0.1.0

First release:

Prepare for release:

  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • Review pkgdown reference index for, e.g., missing topics
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • Finish blog post
  • Tweet
  • Add link to blog post in pkgdown news menu

pkgcheck results - main

Checks for rasterpic (v0.2.2)

git hash: f0267dfa

  • ✔️ Package is already on CRAN.
  • ✔️ has a 'codemeta.json' file.
  • ✔️ has a 'contributing' file.
  • ✔️ uses 'roxygen2'.
  • ✔️ 'DESCRIPTION' has a URL field.
  • ✔️ 'DESCRIPTION' has a BugReports field.
  • ✔️ Package has at least one HTML vignette
  • ✔️ All functions have examples.
  • ✔️ Package has continuous integration checks.
  • ✔️ Package coverage is 100%.
  • ✔️ R CMD check found no errors.
  • ✔️ R CMD check found no warnings.

Package License: MIT + file LICENSE


1. Package Dependencies

Details of Package Dependency Usage (click to open)

The table below tallies all function calls to all packages ('ncalls'), both internal (r-base + recommended, along with the package itself), and external (imported and suggested packages). 'NA' values indicate packages to which no identified calls to R functions could be found. Note that these results are generated by an automated code-tagging system which may not be entirely accurate.

type package ncalls
internal base 24
internal graphics 11
internal rasterpic 9
internal tools 2
internal utils 1
imports terra 9
imports png 1
imports sf 1
suggests ggplot2 NA
suggests knitr NA
suggests rmarkdown NA
suggests testthat NA
suggests tidyterra NA
linking_to NA NA

Click below for tallies of functions used in each package. Locations of each call within this package may be generated locally by running 's <- pkgstats::pkgstats(<path/to/repo>)', and examining the 'external_calls' table.

base

c (4), list (4), nrow (2), paste0 (2), rep (2), row (2), tempfile (2), as.double (1), dim (1), for (1), min (1), seq_len (1), tryCatch (1)

graphics

box (11)

rasterpic

asp_ratio (3), rpic_input (2), rpic_read (2), rasterpic_img (1), rpic_crop (1)

terra

rast (2), ext (1), ncol (1), nrow (1), xmax (1), xmin (1), ymax (1), ymin (1)

tools

file_ext (2)

png

readPNG (1)

sf

st_bbox (1)

utils

download.file (1)


2. Statistical Properties

This package features some noteworthy statistical properties which may need to be clarified by a handling editor prior to progressing.

Details of statistical properties (click to open)

The package has:

  • code in R (100% in 4 files) and
  • 1 authors
  • 2 vignettes
  • no internal data file
  • 3 imported packages
  • 2 exported functions (median 31 lines of code)
  • 10 non-exported functions in R (median 27 lines of code)

Statistical properties of package structure as distributional percentiles in relation to all current CRAN packages
The following terminology is used:

  • loc = "Lines of Code"
  • fn = "function"
  • exp/not_exp = exported / not exported

All parameters are explained as tooltips in the locally-rendered HTML version of this report generated by the checks_to_markdown() function

The final measure (fn_call_network_size) is the total number of calls between functions (in R), or more abstract relationships between code objects in other languages. Values are flagged as "noteworthy" when they lie in the upper or lower 5th percentile.

measure value percentile noteworthy
files_R 4 28.3
files_vignettes 2 85.7
files_tests 12 92.5
loc_R 151 17.0
loc_vignettes 127 33.2
loc_tests 653 80.1
num_vignettes 2 89.2
n_fns_r 12 16.1
n_fns_r_exported 2 6.8
n_fns_r_not_exported 10 22.3
n_fns_per_file_r 2 34.7
num_params_per_fn 5 69.6
loc_per_fn_r 28 74.1
loc_per_fn_r_exp 32 64.9
loc_per_fn_r_not_exp 28 75.7
rel_whitespace_R 30 32.1
rel_whitespace_vignettes 47 45.3
rel_whitespace_tests 38 87.8
doclines_per_fn_exp 69 79.2
doclines_per_fn_not_exp 0 0.0 TRUE
fn_call_network_size 5 22.6

2a. Network visualisation

An interactive visualisation of calls between objects in the package has been uploaded as a workflow artefact. To view it, click on results from the latest 'pkgcheck' action, scroll to the bottom, and click on the 'visual-network' artefact.


3. goodpractice and other checks

Details of goodpractice checks (click to open)

3a. Continuous Integration Badges

check-full.yaml

GitHub Workflow Results

id name conclusion sha run_number date
5737601596 CRAN Status Monitor success 053339 72 2023-08-02
5738849198 lintr success f0267d 1 2023-08-02
5738927152 pages build and deployment success 6864b3 90 2023-08-02
5738994636 pkgcheck NA f0267d 1 2023-08-02
5738849202 pkgdown-gh-pages success f0267d 69 2023-08-02
5738849197 R-CMD-check success f0267d 242 2023-08-02
5738849201 test-coverage success f0267d 88 2023-08-02
5713081278 update-docs success 9d5b11 35 2023-07-31

3b. goodpractice results

R CMD check with rcmdcheck

rcmdcheck found no errors, warnings, or notes

Test coverage with covr

Package coverage: 100

Cyclocomplexity with cyclocomp

The following function have cyclocomplexity >= 15:

function cyclocomplexity
rpic_input 17

Static code analyses with lintr

lintr found the following 12 potential issues:

message number of times
Avoid library() and require() calls in packages 12


Package Versions

package version
pkgstats 0.1.3.4
pkgcheck 0.1.2.1

URGENT! Failed CRAN Checks: 2023-02-03

CRAN checks for rasterpic resulted in one or more (WARNING,ERROR)s:

See the table below for a summary of the checks run by CRAN:

Flavor Version Tinstall Tcheck Ttotal Status Flags
r-devel-linux-x86_64-debian-clang 0.2.1 2.31 79.30 81.61 OK NA
r-devel-linux-x86_64-debian-gcc 0.2.1 2.07 58.35 60.42 OK NA
r-devel-linux-x86_64-fedora-clang 0.2.1 NA NA 96.22 OK NA
r-devel-linux-x86_64-fedora-gcc 0.2.1 NA NA 105.26 OK NA
r-devel-windows-x86_64 0.2.1 16.00 111.00 127.00 ERROR NA
r-patched-linux-x86_64 0.2.1 2.70 73.26 75.96 OK NA
r-release-linux-x86_64 0.2.1 2.66 76.39 79.05 OK NA
r-release-macos-arm64 0.2.1 NA NA 36.00 OK NA
r-release-macos-x86_64 0.2.1 NA NA 42.00 OK NA
r-release-windows-x86_64 0.2.1 13.00 116.00 129.00 OK NA
r-oldrel-macos-arm64 0.2.1 NA NA 27.00 OK NA
r-oldrel-macos-x86_64 0.2.1 NA NA 43.00 OK NA
r-oldrel-windows-ix86+x86_64 0.2.1 7.00 110.00 117.00 OK NA

All details and logs are available here: https://cran.r-project.org/web/checks/check_results_rasterpic.html

Release rasterpic 0.2.4

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Polish NEWS
  • urlchecker::url_check()
  • devtools::build_readme()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • git push
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('major')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • Finish & publish blog post
  • Add link to blog post in pkgdown news menu
  • usethis::use_github_release()
  • usethis::use_dev_version(push = TRUE)
  • Tweet

Release rasterpic 0.2.0

Prepare for release:

  • Check current CRAN check results
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • Review pkgdown reference index for, e.g., missing topics
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • Finish blog post
  • Tweet
  • Add link to blog post in pkgdown news menu

Release rasterpic 0.2.5

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Polish NEWS
  • urlchecker::url_check()
  • devtools::build_readme()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • git push

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version(push = TRUE)

Release rasterpic 0.2.2

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • git push

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • git push
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • git push

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.