Skip to content

Commit

Permalink
gpkg_contents: deprecate template argument
Browse files Browse the repository at this point in the history
  • Loading branch information
brownag committed Mar 3, 2024
1 parent be82dc8 commit fa5b16f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
24 changes: 21 additions & 3 deletions R/gpkg-contents.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,35 @@ gpkg_list_contents <- function(x, ogr = FALSE) {

#' Add, Remove, Update and Create `gpkg_contents` table and records
#' @description `gpkg_add_contents()`: Add a record to `gpkg_contents`
#'
#' @param x A _geopackage_
#' @param table_name Name of table to add or remove record for in _gpkg_contents_
#' @param description Default `""`
#' @param template Default `NULL` uses global EPSG:4326 with bounds -180,-90:180,90
#' @param description Default: `""`
#' @param template Deprecated. A list containing elements `"srsid"` and `"ext"`.
#' @param srs_id _integer_. Spatial Reference System ID. Must be defined in `gpkg_spatial_ref_sys` table.
#' @param ext _numeric_. A numeric vector of length four specifying the bounding box extent.
#' @param query_string _logical_. Return SQLite statement rather than executing it? Default: `FALSE`
#'
#' @return logical. TRUE on successful execution of SQL statements.
#' @rdname gpkg-contents
#' @export
gpkg_add_contents <- function(x, table_name, description = "", template = NULL, query_string = FALSE) {
gpkg_add_contents <- function(x, table_name, description = "", srs_id = NULL, ext = NULL, template = NULL, query_string = FALSE) {
dt <- NULL

if (!missing(srs_id) && !is.null(srs_id)) {
if (!length(srs_id) == 1 || !is.integer(as.integer(srs_id)))
stop("`srs_id` should be an integer of length 1")
cr <- srs_id
}

if (!missing(ext) && !is.null(ext)) {
if (!length(ext) == 4 || !is.numeric(ext))
stop("`ext` should be a numeric vector of length 4")
ex <- ext
}

if (!missing(template) && !is.null(template)) {
.Deprecated(msg = "`template` argument is deprecated, use `ext` and `srs_id` arguments directly")
# template as a list
if (is.list(template) && all(c("ext", "srsid") %in% names(template))) {
ex <- template$ext
Expand Down
5 changes: 2 additions & 3 deletions inst/tinytest/test_gpkg.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ expect_true(gpkg_create_contents(g3))

# add dummy row
expect_true(gpkg_add_contents(g3, "foo", "bar",
template = list(
ext = c(0, 0, 0, 0),
srsid = 4326
)))
srs_id = 4326
))

# add dummy attribute table
expect_true(gpkg_write_attributes(g3, data.frame(id = 1), "A", "the letter A"))
Expand Down
10 changes: 8 additions & 2 deletions man/gpkg-contents.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fa5b16f

Please sign in to comment.