diff --git a/.Rbuildignore b/.Rbuildignore index 12dbc9d..8f45c67 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -8,4 +8,6 @@ ^LICENSE.md ^_pkgdown.yml ^hexlogo_transparent.png -^pkgdown \ No newline at end of file +^pkgdown +^CODE_OF_CONDUCT\.md$ +^CITATION\.cff$ diff --git a/CITATION.cff b/CITATION.cff new file mode 100644 index 0000000..c573ad8 --- /dev/null +++ b/CITATION.cff @@ -0,0 +1,393 @@ +# ----------------------------------------------------------- +# CITATION file created with {cffr} R package, v0.5.0 +# See also: https://docs.ropensci.org/cffr/ +# ----------------------------------------------------------- + +cff-version: 1.2.0 +message: 'To cite package "quadkeyr" in publications use:' +type: software +license: MIT +title: 'quadkeyr: Tools to convert QuadKeys utilized in Microsoft''s Bing Maps Tile + System into raster images' +version: 0.0.0.9000 +abstract: quadkeyr enables the generation of raster images based on QuadKeys, facilitating + efficient integration of Bing Maps data into R workflows. In particular, quadkeyr + provides support to process and analyze Facebook mobility datasets within the R + environment. +authors: +- family-names: D'Andrea + given-names: Florencia + email: florencia.dandrea@gmail.com + orcid: https://orcid.org/0000-0002-0041-097X +repository-code: https://github.com/Fernandez-Lab-WSU/quadkeyr +url: https://fernandez-lab-wsu.github.io/quadkeyr/ +contact: +- family-names: D'Andrea + given-names: Florencia + email: florencia.dandrea@gmail.com + orcid: https://orcid.org/0000-0002-0041-097X +keywords: +- geospatial +- quadkey +- raster +- rstats +- tilemap +references: +- type: software + title: knitr + abstract: 'knitr: A General-Purpose Package for Dynamic Report Generation in R' + notes: Suggests + url: https://yihui.org/knitr/ + repository: https://CRAN.R-project.org/package=knitr + authors: + - family-names: Xie + given-names: Yihui + email: xie@yihui.name + orcid: https://orcid.org/0000-0003-0645-5666 + year: '2023' +- type: software + title: rmarkdown + abstract: 'rmarkdown: Dynamic Documents for R' + notes: Suggests + url: https://pkgs.rstudio.com/rmarkdown/ + repository: https://CRAN.R-project.org/package=rmarkdown + authors: + - family-names: Allaire + given-names: JJ + email: jj@posit.co + - family-names: Xie + given-names: Yihui + email: xie@yihui.name + orcid: https://orcid.org/0000-0003-0645-5666 + - family-names: Dervieux + given-names: Christophe + email: cderv@posit.co + orcid: https://orcid.org/0000-0003-4474-2498 + - family-names: McPherson + given-names: Jonathan + email: jonathan@posit.co + - family-names: Luraschi + given-names: Javier + - family-names: Ushey + given-names: Kevin + email: kevin@posit.co + - family-names: Atkins + given-names: Aron + email: aron@posit.co + - family-names: Wickham + given-names: Hadley + email: hadley@posit.co + - family-names: Cheng + given-names: Joe + email: joe@posit.co + - family-names: Chang + given-names: Winston + email: winston@posit.co + - family-names: Iannone + given-names: Richard + email: rich@posit.co + orcid: https://orcid.org/0000-0003-3925-190X + year: '2023' +- type: software + title: testthat + abstract: 'testthat: Unit Testing for R' + notes: Suggests + url: https://testthat.r-lib.org + repository: https://CRAN.R-project.org/package=testthat + authors: + - family-names: Wickham + given-names: Hadley + email: hadley@posit.co + year: '2023' + version: '>= 3.1.10' +- type: software + title: 'R: A Language and Environment for Statistical Computing' + notes: Depends + url: https://www.R-project.org/ + authors: + - name: R Core Team + location: + name: Vienna, Austria + year: '2023' + institution: + name: R Foundation for Statistical Computing + version: '>= 2.10' +- type: software + title: bslib + abstract: 'bslib: Custom ''Bootstrap'' ''Sass'' Themes for ''shiny'' and ''rmarkdown''' + notes: Imports + url: https://rstudio.github.io/bslib/ + repository: https://CRAN.R-project.org/package=bslib + authors: + - family-names: Sievert + given-names: Carson + email: carson@posit.co + orcid: https://orcid.org/0000-0002-4958-2844 + - family-names: Cheng + given-names: Joe + email: joe@posit.co + - family-names: Aden-Buie + given-names: Garrick + email: garrick@posit.co + orcid: https://orcid.org/0000-0002-7111-0077 + year: '2023' + version: '>= 0.5.1' +- type: software + title: dplyr + abstract: 'dplyr: A Grammar of Data Manipulation' + notes: Imports + url: https://dplyr.tidyverse.org + repository: https://CRAN.R-project.org/package=dplyr + authors: + - family-names: Wickham + given-names: Hadley + email: hadley@posit.co + orcid: https://orcid.org/0000-0003-4757-117X + - family-names: François + given-names: Romain + orcid: https://orcid.org/0000-0002-2444-4226 + - family-names: Henry + given-names: Lionel + - family-names: Müller + given-names: Kirill + orcid: https://orcid.org/0000-0002-1416-3412 + - family-names: Vaughan + given-names: Davis + email: davis@posit.co + orcid: https://orcid.org/0000-0003-4777-038X + year: '2023' + version: '>= 1.1.2' +- type: software + title: DT + abstract: 'DT: A Wrapper of the JavaScript Library ''DataTables''' + notes: Imports + url: https://github.com/rstudio/DT + repository: https://CRAN.R-project.org/package=DT + authors: + - family-names: Xie + given-names: Yihui + email: xie@yihui.name + - family-names: Cheng + given-names: Joe + - family-names: Tan + given-names: Xianying + year: '2023' + version: '>= 0.27' +- type: software + title: ggplot2 + abstract: 'ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics' + notes: Imports + url: https://ggplot2.tidyverse.org + repository: https://CRAN.R-project.org/package=ggplot2 + authors: + - family-names: Wickham + given-names: Hadley + email: hadley@posit.co + orcid: https://orcid.org/0000-0003-4757-117X + - family-names: Chang + given-names: Winston + orcid: https://orcid.org/0000-0002-1576-2126 + - family-names: Henry + given-names: Lionel + - family-names: Pedersen + given-names: Thomas Lin + email: thomas.pedersen@posit.co + orcid: https://orcid.org/0000-0002-5147-4711 + - family-names: Takahashi + given-names: Kohske + - family-names: Wilke + given-names: Claus + orcid: https://orcid.org/0000-0002-7470-9261 + - family-names: Woo + given-names: Kara + orcid: https://orcid.org/0000-0002-5125-4188 + - family-names: Yutani + given-names: Hiroaki + orcid: https://orcid.org/0000-0002-3385-7233 + - family-names: Dunnington + given-names: Dewey + orcid: https://orcid.org/0000-0002-9415-4582 + year: '2023' + version: '>= 3.4.3' +- type: software + title: leaflet + abstract: 'leaflet: Create Interactive Web Maps with the JavaScript ''Leaflet'' + Library' + notes: Imports + url: https://rstudio.github.io/leaflet/ + repository: https://CRAN.R-project.org/package=leaflet + authors: + - family-names: Cheng + given-names: Joe + email: joe@posit.co + - family-names: Schloerke + given-names: Barret + email: barret@posit.co + orcid: https://orcid.org/0000-0001-9986-114X + - family-names: Karambelkar + given-names: Bhaskar + - family-names: Xie + given-names: Yihui + year: '2023' + version: '>= 2.2.0' +- type: software + title: lubridate + abstract: 'lubridate: Make Dealing with Dates a Little Easier' + notes: Imports + url: https://lubridate.tidyverse.org + repository: https://CRAN.R-project.org/package=lubridate + authors: + - family-names: Spinu + given-names: Vitalie + email: spinuvit@gmail.com + - family-names: Grolemund + given-names: Garrett + - family-names: Wickham + given-names: Hadley + year: '2023' + version: '>= 1.9.2' +- type: software + title: purrr + abstract: 'purrr: Functional Programming Tools' + notes: Imports + url: https://purrr.tidyverse.org/ + repository: https://CRAN.R-project.org/package=purrr + authors: + - family-names: Wickham + given-names: Hadley + email: hadley@rstudio.com + orcid: https://orcid.org/0000-0003-4757-117X + - family-names: Henry + given-names: Lionel + email: lionel@rstudio.com + year: '2023' + version: '>= 1.0.1' +- type: software + title: readr + abstract: 'readr: Read Rectangular Text Data' + notes: Imports + url: https://readr.tidyverse.org + repository: https://CRAN.R-project.org/package=readr + authors: + - family-names: Wickham + given-names: Hadley + email: hadley@posit.co + - family-names: Hester + given-names: Jim + - family-names: Bryan + given-names: Jennifer + email: jenny@posit.co + orcid: https://orcid.org/0000-0002-6983-2759 + year: '2023' + version: '>= 2.1.4' +- type: software + title: rnaturalearth + abstract: 'rnaturalearth: World Map Data from Natural Earth' + notes: Imports + url: https://docs.ropensci.org/rnaturalearth/ + repository: https://CRAN.R-project.org/package=rnaturalearth + authors: + - family-names: Massicotte + given-names: Philippe + email: pmassicotte@hotmail.com + orcid: https://orcid.org/0000-0002-5919-4116 + - family-names: South + given-names: Andy + email: southandy@gmail.com + year: '2023' + version: '>= 0.3.2' +- type: software + title: sf + abstract: 'sf: Simple Features for R' + notes: Imports + url: https://r-spatial.github.io/sf/ + repository: https://CRAN.R-project.org/package=sf + authors: + - family-names: Pebesma + given-names: Edzer + email: edzer.pebesma@uni-muenster.de + orcid: https://orcid.org/0000-0001-8049-7069 + year: '2023' + version: '>= 1.0.14' +- type: software + title: shiny + abstract: 'shiny: Web Application Framework for R' + notes: Imports + url: https://shiny.rstudio.com/ + repository: https://CRAN.R-project.org/package=shiny + authors: + - family-names: Chang + given-names: Winston + email: winston@rstudio.com + orcid: https://orcid.org/0000-0002-1576-2126 + - family-names: Cheng + given-names: Joe + email: joe@rstudio.com + - family-names: Allaire + given-names: JJ + email: jj@rstudio.com + - family-names: Sievert + given-names: Carson + email: carson@rstudio.com + orcid: https://orcid.org/0000-0002-4958-2844 + - family-names: Schloerke + given-names: Barret + email: barret@rstudio.com + orcid: https://orcid.org/0000-0001-9986-114X + - family-names: Xie + given-names: Yihui + email: yihui@rstudio.com + - family-names: Allen + given-names: Jeff + email: jeff@rstudio.com + - family-names: McPherson + given-names: Jonathan + email: jonathan@rstudio.com + - family-names: Dipert + given-names: Alan + - family-names: Borges + given-names: Barbara + year: '2023' + version: '>= 1.7.4' +- type: software + title: stars + abstract: 'stars: Spatiotemporal Arrays, Raster and Vector Data Cubes' + notes: Imports + url: https://r-spatial.github.io/stars/ + repository: https://CRAN.R-project.org/package=stars + authors: + - family-names: Pebesma + given-names: Edzer + email: edzer.pebesma@uni-muenster.de + orcid: https://orcid.org/0000-0001-8049-7069 + year: '2023' + version: '>= 0.6.2' +- type: software + title: tidyr + abstract: 'tidyr: Tidy Messy Data' + notes: Imports + url: https://tidyr.tidyverse.org + repository: https://CRAN.R-project.org/package=tidyr + authors: + - family-names: Wickham + given-names: Hadley + email: hadley@posit.co + - family-names: Vaughan + given-names: Davis + email: davis@posit.co + - family-names: Girlich + given-names: Maximilian + year: '2023' + version: '>= 1.3.0' +- type: software + title: viridis + abstract: 'viridis: Colorblind-Friendly Color Maps for R' + notes: Imports + url: https://sjmgarnier.github.io/viridis/ + repository: https://CRAN.R-project.org/package=viridis + authors: + - family-names: Garnier + given-names: Simon + email: garnier@njit.edu + year: '2023' + version: '>= 0.6.4' diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..5f01295 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,126 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, + without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at florencia.dandrea@gmail.com. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][https://github.com/mozilla/inclusion]. + +For answers to common questions about this code of conduct, see the FAQ at +. Translations are available at . + +[homepage]: https://www.contributor-covenant.org diff --git a/DESCRIPTION b/DESCRIPTION index bf736ff..1cd5e97 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,6 +9,8 @@ Authors@R: comment = c(ORCID = "0000-0002-0041-097X")) Description: quadkeyr enables the generation of raster images based on QuadKeys, facilitating efficient integration of Bing Maps data into R workflows. In particular, quadkeyr provides support to process and analyze Facebook mobility datasets within the R environment. License: MIT + file LICENSE +URL: https://fernandez-lab-wsu.github.io/quadkeyr/, https://github.com/Fernandez-Lab-WSU/quadkeyr +BugReports: https://github.com/Fernandez-Lab-WSU/quadkeyr/issues Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.1 diff --git a/NAMESPACE b/NAMESPACE index 8479117..d9c0ed9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ export(clip) export(complete_grid_for_polygons) export(create_qk_grid) export(create_raster) +export(extract_qk_coord) export(extract_tile_coord) export(format_data) export(grid_to_polygon) diff --git a/R/extract_coords.R b/R/extract_coords.R index 2c16116..988416c 100644 --- a/R/extract_coords.R +++ b/R/extract_coords.R @@ -13,7 +13,7 @@ #' (tileX, tileY), the QuadKey number (quadkey), and a column for POINT #' geometry. #' -#'#' @export +#' @export #' #' @examples #' @@ -42,7 +42,7 @@ extract_qk_coord <- function(data){ data$qk_tileY[i] <- qktot$tileY ttop <- tileXY_to_pixelXY(tileX = data$qk_tileX[i], - tileY = data$qk_tileY[i]) + tileY = data$qk_tileY[i]) data$tl_pxx[i] <- ttop$pixelX data$tl_pxy[i] <- ttop$pixelY diff --git a/README.Rmd b/README.Rmd index cdafb0f..4fb59d1 100644 --- a/README.Rmd +++ b/README.Rmd @@ -17,7 +17,7 @@ knitr::opts_chunk$set( -[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) +[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) [![test-coverage](https://github.com/Fernandez-Lab-WSU/quadkeyr/actions/workflows/test-coverage.yaml/badge.svg)](https://github.com/Fernandez-Lab-WSU/quadkeyr/actions/workflows/test-coverage.yaml) [![R-CMD-check](https://github.com/Fernandez-Lab-WSU/quadkeyr/actions/workflows/check-standard.yaml/badge.svg)](https://github.com/Fernandez-Lab-WSU/quadkeyr/actions/workflows/check-standard.yaml) [![Codecov](https://img.shields.io/codecov/c/github/Fernandez-Lab-WSU/quadkeyr)](https://codecov.io/gh/Fernandez-Lab-WSU/quadkeyr) ⚠️ This package is under review @@ -57,6 +57,11 @@ You can install the development version of `quadkeyr` from [GitHub](https://gith devtools::install_github("Fernandez-Lab-WSU/quadkeyr") ``` +## Code of Conduct + +Please note that the `quadkeyr` 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. + +### How to cite this package? ### References - [Bing Maps Tile Systems - Microsoft](https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system) diff --git a/README.md b/README.md index d2e0fa5..1e35631 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,9 @@ [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) +[![test-coverage](https://github.com/Fernandez-Lab-WSU/quadkeyr/actions/workflows/test-coverage.yaml/badge.svg)](https://github.com/Fernandez-Lab-WSU/quadkeyr/actions/workflows/test-coverage.yaml) +[![R-CMD-check](https://github.com/Fernandez-Lab-WSU/quadkeyr/actions/workflows/check-standard.yaml/badge.svg)](https://github.com/Fernandez-Lab-WSU/quadkeyr/actions/workflows/check-standard.yaml) +[![Codecov](https://img.shields.io/codecov/c/github/Fernandez-Lab-WSU/quadkeyr)](https://codecov.io/gh/Fernandez-Lab-WSU/quadkeyr) ⚠️ This package is under review @@ -24,10 +27,10 @@ data](https://dataforgood.facebook.com/). The goal of `quadkeyr` is to: -1. [**Bing Maps Tile System +1. [**Provide Bing Maps Tile System functions**](https://fernandez-lab-wsu.github.io/quadkeyr/articles/quadkey_conversion.html) - Provide functions in R to convert geographical coordinates to and - from QuadKeys as described in the [official + R functions to convert geographical coordinates to and from QuadKeys + as described in the [official documentation](https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system) 2. [**Create rasters based on @@ -54,6 +57,15 @@ You can install the development version of `quadkeyr` from devtools::install_github("Fernandez-Lab-WSU/quadkeyr") ``` +## Code of Conduct + +Please note that the `quadkeyr` 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. + +### How to cite this package? + ### References - [Bing Maps Tile Systems - diff --git a/figure/unnamed-chunk-2-1.png b/figure/unnamed-chunk-2-1.png new file mode 100644 index 0000000..d03d3ec Binary files /dev/null and b/figure/unnamed-chunk-2-1.png differ diff --git a/figure/unnamed-chunk-3-1.png b/figure/unnamed-chunk-3-1.png new file mode 100644 index 0000000..c2c23d0 Binary files /dev/null and b/figure/unnamed-chunk-3-1.png differ diff --git a/figure/unnamed-chunk-4-1.png b/figure/unnamed-chunk-4-1.png new file mode 100644 index 0000000..c65ff5e Binary files /dev/null and b/figure/unnamed-chunk-4-1.png differ diff --git a/figure/unnamed-chunk-8-1.png b/figure/unnamed-chunk-8-1.png new file mode 100644 index 0000000..06188b2 Binary files /dev/null and b/figure/unnamed-chunk-8-1.png differ diff --git a/inst/CITATION b/inst/CITATION deleted file mode 100644 index 76c6e6b..0000000 --- a/inst/CITATION +++ /dev/null @@ -1,22 +0,0 @@ -citHeader("To cite quadkeyr in publications use:") - -year <- sub("-.*", "", meta$Date) -note <- sprintf("R package version %s", meta$Version) -authors <- eval(parse(text = meta$`Authors@R`)) -text_authors <- authors |> - format(include= c("family", "given"), - collapse = list(family = ", ")) |> - paste(collapse = ", ") - -bibentry( - bibtype = "Manual", - title = sprintf("{%s}: %s", meta$Package, meta$Title), - author = authors, - year = year, - note = note, - url = meta$URL, - textVersion = sprintf( - "%s, (%s). %s: %s. %s, %s", - text_authors, year, meta$Package, meta$Title, note, meta$URL - ) -) diff --git a/man/extract_qk_coord.Rd b/man/extract_qk_coord.Rd index da10062..566e65d 100644 --- a/man/extract_qk_coord.Rd +++ b/man/extract_qk_coord.Rd @@ -13,8 +13,6 @@ extract_qk_coord(data) A spatial dataframe (sf) containing the tiles XY coordinates (tileX, tileY), the QuadKey number (quadkey), and a column for POINT geometry. - -#' @export } \description{ Reads the QuadKey number as a string to extract the diff --git a/vignettes/get_grid_from_quadkeys.Rmd b/vignettes/get_grid_from_quadkeys.Rmd index 0250e28..08bcc97 100644 --- a/vignettes/get_grid_from_quadkeys.Rmd +++ b/vignettes/get_grid_from_quadkeys.Rmd @@ -7,16 +7,7 @@ vignette: > %\VignetteEncoding{UTF-8} --- -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>", - warning = FALSE, - message = FALSE, - fig.width=7, - fig.height=7 -) -``` + @@ -26,14 +17,7 @@ knitr::opts_chunk$set( #### 1.1 Define the area -```{r setup, echo = FALSE} -library(quadkeyr) -library(sf) -library(rnaturalearth) -library(ggplot2) -library(dplyr) -library(stars) -``` + First, we should define the `xmin`, `xmax`, `ymin` and `ymax` that will delimit the area for the QuadKey grid creation. @@ -41,25 +25,7 @@ the area for the QuadKey grid creation. For this example, we have selected `xmin` = -59, `xmax` = -57, `ymin` = -35, `ymax` = -34. Let's plot them as points. -```{r echo=FALSE} - - -ggplot() + - geom_sf(data = ne_countries(returnclass = 'sf'), - fill = 'beige') + - geom_point(aes(x = -59, y = -35 ), color = 'purple') + - geom_point(aes(x = -57, y = -34), color = 'purple') + - coord_sf(xlim = c(-60, -56), - ylim = c(-36, -33), expand = FALSE) + - theme_minimal() + - theme(panel.background = element_rect(fill = "lightblue"), - panel.ontop = FALSE, - panel.grid.major = element_blank(), - panel.grid.minor = element_blank()) + - ylab("Latitude") + - xlab("Longitude") - -``` +![plot of chunk unnamed-chunk-2](figure/unnamed-chunk-2-1.png) #### 1.2 Select the level of detail @@ -75,7 +41,8 @@ each element of the grid 3. `grid$num_cols` the number of columns of the grid. -```{r cqg} + +```r grid <- create_qk_grid( xmin = -59, xmax = -57, @@ -83,7 +50,13 @@ grid <- create_qk_grid( ymax = -34, level = 12) head(grid$data) - +#> tileX tileY quadkey +#> 1 1376 2473 210321302002 +#> 2 1376 2472 210321302000 +#> 3 1376 2471 210321300222 +#> 4 1376 2470 210321300220 +#> 5 1376 2469 210321300202 +#> 6 1376 2468 210321300200 ``` #### 1.3 Get the grid coordinates from the QuadKeys @@ -91,34 +64,26 @@ head(grid$data) The coordinates are extracted from the QuadKeys using the function `extract_qk_coords()` -```{r grid} + +```r grid_coords <- extract_qk_coord(data = grid$data) head(grid_coords) +#> Simple feature collection with 6 features and 3 fields +#> Geometry type: POINT +#> Dimension: XY +#> Bounding box: xmin: -59.0625 ymin: -34.958 xmax: -59.0625 ymax: -34.59704 +#> Geodetic CRS: WGS 84 +#> tileX tileY quadkey geometry +#> 1 1376 2473 210321302002 POINT (-59.0625 -34.958) +#> 2 1376 2472 210321302000 POINT (-59.0625 -34.88593) +#> 3 1376 2471 210321300222 POINT (-59.0625 -34.8138) +#> 4 1376 2470 210321300220 POINT (-59.0625 -34.74161) +#> 5 1376 2469 210321300202 POINT (-59.0625 -34.66936) +#> 6 1376 2468 210321300200 POINT (-59.0625 -34.59704) ``` We can visualize the points in the map to understand better the results. -```{r echo = FALSE} - - -min =st_sfc(st_point(c(-59,-35)), crs = 4326) -max = st_sfc(st_point(c(-57,-34)), crs = 4326) -ggplot() + - geom_sf(data = ne_countries(returnclass = 'sf'), - fill = 'beige') + - - geom_sf(data = min, color = 'purple') + - geom_sf(data = max, color = 'purple') + - geom_sf(data = grid_coords, alpha = 0.5, size = 0.5) + - coord_sf(xlim = c(-60, -56), - ylim = c(-36, -33), expand = FALSE) + - theme_minimal() + - theme(panel.background = element_rect(fill = "lightblue"), - panel.ontop = FALSE, - panel.grid.major = element_blank(), - panel.grid.minor = element_blank()) + - ylab("Latitude") + - xlab("Longitude") -``` +![plot of chunk unnamed-chunk-3](figure/unnamed-chunk-3-1.png) We have a grid of points representing the QuadKeys. Remember that these points represent the upper-left corner of each QuadKey, which might give the impression that they do not precisely cover the entire area. @@ -127,34 +92,24 @@ that they do not precisely cover the entire area. #### 1.4 Conversion to polygons Now, let's proceed to create the polygons. -```{r poly} + +```r polygrid = grid_to_polygon(grid_coords) head(polygrid) - -``` -```{r echo = FALSE} - -min =st_sfc(st_point(c(-59,-35)), crs = 4326) -max = st_sfc(st_point(c(-57,-34)), crs = 4326) -ggplot() + - geom_sf(data = ne_countries(returnclass = 'sf'), - fill = 'beige') + - - geom_sf(data = min, color = 'purple') + - geom_sf(data = max, color = 'purple') + - geom_sf(data = polygrid, alpha = 0.5, - size = 0.5, fill = NA, color = 'red') + - coord_sf(xlim = c(-60, -56), - ylim = c(-36, -33), expand = FALSE) + - theme_minimal() + - theme(panel.background = element_rect(fill = "lightblue"), - panel.ontop = FALSE, - panel.grid.major = element_blank(), - panel.grid.minor = element_blank()) + - ylab("Latitude") + - xlab("Longitude") - +#> Simple feature collection with 6 features and 1 field +#> Geometry type: POLYGON +#> Dimension: XY +#> Bounding box: xmin: -57.04102 ymin: -34.37971 xmax: -56.95312 ymax: -33.94336 +#> Geodetic CRS: WGS 84 +#> quadkey geometry +#> 1 210321132133 POLYGON ((-57.04102 -34.016... +#> 2 210321132311 POLYGON ((-57.04102 -34.089... +#> 3 210321132313 POLYGON ((-57.04102 -34.161... +#> 4 210321132331 POLYGON ((-57.04102 -34.234... +#> 5 210321132333 POLYGON ((-57.04102 -34.307... +#> 6 210321310111 POLYGON ((-57.04102 -34.379... ``` +![plot of chunk unnamed-chunk-4](figure/unnamed-chunk-4-1.png) It worked! As you can see here, the coordinates we randomly selected as a starting point are situated within the polygons, but not at a @@ -162,7 +117,8 @@ specific position inside each polygon. This was expected. If you want to see the grid, you can also check the app: -```{r eval = FALSE} + +```r qkmap_app() @@ -177,10 +133,17 @@ Let's generate the raster. The `data_provided` dataset consists of QuadKeys linked to a variable value. While this dataset contains QuadKeys within our defined study area and detail level, not all grid QuadKeys are present. -```{r} + +```r data('data_provided') head(data_provided) - +#> quadkey variable +#> 1 210321132133 0.22 +#> 2 210321132311 0.56 +#> 3 210321132313 0.27 +#> 4 210321132331 0.06 +#> 5 210321132333 0.88 +#> 6 210321310111 0.22 ``` @@ -188,18 +151,31 @@ I merge `polygrid` and `data_provided` using QuadKey as the key. Please note that `data_provided` shouldn't be an `sf` dataset with a geometry column for this join to be executed correctly. -```{r dp} + +```r data_raster <- polygrid |> dplyr::inner_join(data_provided, by = c('quadkey')) head(data_raster) - +#> Simple feature collection with 6 features and 2 fields +#> Geometry type: POLYGON +#> Dimension: XY +#> Bounding box: xmin: -57.04102 ymin: -34.37971 xmax: -56.95312 ymax: -33.94336 +#> Geodetic CRS: WGS 84 +#> quadkey variable geometry +#> 1 210321132133 0.22 POLYGON ((-57.04102 -34.016... +#> 2 210321132311 0.56 POLYGON ((-57.04102 -34.089... +#> 3 210321132313 0.27 POLYGON ((-57.04102 -34.161... +#> 4 210321132331 0.06 POLYGON ((-57.04102 -34.234... +#> 5 210321132333 0.88 POLYGON ((-57.04102 -34.307... +#> 6 210321310111 0.22 POLYGON ((-57.04102 -34.379... ``` Now, we can use the dataframe to create the raster. -```{r} + +```r raster <- create_raster(template = data_raster, nx = grid$num_cols +1, ny = grid$num_rows +1, @@ -207,40 +183,20 @@ raster <- create_raster(template = data_raster, var = 'variable') raster +#> stars object with 2 dimensions and 1 attribute +#> attribute(s): +#> Min. 1st Qu. Median Mean 3rd Qu. Max. +#> variable 0 0.22 0.49 0.5028611 0.76 1 +#> dimension(s): +#> from to offset delta refsys point x/y +#> x 1 24 -59.06 0.08789 WGS 84 FALSE [x] +#> y 1 15 -33.94 -0.07244 WGS 84 FALSE [y] # In case you want to save it: # write_stars(obj = raster, # dsn = "raster.tif") - ``` -```{r echo = FALSE} - - -min =st_sfc(st_point(c(-59,-35)), crs = 4326) -max = st_sfc(st_point(c(-57,-34)), crs = 4326) -p = ggplot() + - geom_sf(data = ne_countries(returnclass = 'sf'), - fill = 'beige') + - - geom_sf(data = min, color = 'purple') + - geom_sf(data = max, color = 'purple') + - geom_stars(data = raster, alpha = 0.5) + - geom_sf(data = polygrid, alpha = 0.5, - size = 0.5, color = 'red', fill = NA) + - coord_sf(xlim = c(-60, -56), - ylim = c(-36, -33), expand = FALSE) + - viridis::scale_fill_viridis() + - theme_minimal() + - theme(panel.background = element_rect(fill = "lightblue"), - panel.ontop = FALSE, - panel.grid.major = element_blank(), - panel.grid.minor = element_blank()) + - ylab("Latitude") + - xlab("Longitude") - -p - -``` +![plot of chunk unnamed-chunk-8](figure/unnamed-chunk-8-1.png)