knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of grtsdb
is to create a spatially balanced sample based on the 'Generalised Random Tesselation Stratified' strategy.
We store the base schema in an SQLite database to make the sampling reproducible.
Sampling the same database with the same parameters yields a stable sample.
To install the latest stable version use
# activate the INBO r-universe options( repos = c( INBO = 'https://inbo.r-universe.dev', CRAN = 'https://cloud.r-project.org' ) ) install.packages("grtsdb")
You can install the development version from GitHub with:
# install.packages("remotes") remotes::install_github("inbo/grtsdb")
This is a basic example.
Connect to a database.
tmp_copy <- tempfile(pattern = "grts", fileext = ".sqlite") if (system.file("grts.sqlite", package = "grtsdb") != "") { file.copy(system.file("grts.sqlite", package = "grtsdb"), tmp_copy) } library(grtsdb) db <- connect_db(tmp_copy)
To extract a sample, you'll need to specify the bounding box in projected coordinates and the size of the grid cells.
bbox <- rbind( c(0, 32), c(0, 32) ) extract_sample(grtsdb = db, samplesize = 10, bbox = bbox, cellsize = 1)
Repeating the sample yields the same results.
extract_sample(grtsdb = db, samplesize = 10, bbox = bbox, cellsize = 1)
drop_legacy_sites(grtsdb = db, level = 5)
You can add legacy sites to the sampling scheme.
legacy <- rbind( c(4, 4), c(17, 6) ) add_legacy_sites(legacy, bbox = bbox, cellsize = 1, grtsdb = db) extract_legacy_sample(grtsdb = db, samplesize = 10, bbox = bbox, cellsize = 1)
You can compact the database for storage.
compact_db(db)
Disconnect the database when done.
dbDisconnect(db)
dir.create("inst", showWarnings = FALSE) file.copy(tmp_copy, file.path("inst", "grts.sqlite"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.