From fa5b16f81b5dcaaa7a22b8115f95947106d7601a Mon Sep 17 00:00:00 2001 From: Andrew Gene Brown Date: Sun, 3 Mar 2024 13:40:53 -0800 Subject: [PATCH] gpkg_contents: deprecate `template` argument --- R/gpkg-contents.R | 24 +++++++++++++++++++++--- inst/tinytest/test_gpkg.R | 5 ++--- man/gpkg-contents.Rd | 10 ++++++++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/R/gpkg-contents.R b/R/gpkg-contents.R index 598ad6a..d77be21 100644 --- a/R/gpkg-contents.R +++ b/R/gpkg-contents.R @@ -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 diff --git a/inst/tinytest/test_gpkg.R b/inst/tinytest/test_gpkg.R index 2d6a9da..8aceef2 100644 --- a/inst/tinytest/test_gpkg.R +++ b/inst/tinytest/test_gpkg.R @@ -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")) diff --git a/man/gpkg-contents.Rd b/man/gpkg-contents.Rd index 512e0d1..29a6a49 100644 --- a/man/gpkg-contents.Rd +++ b/man/gpkg-contents.Rd @@ -11,6 +11,8 @@ gpkg_add_contents( x, table_name, description = "", + srs_id = NULL, + ext = NULL, template = NULL, query_string = FALSE ) @@ -26,9 +28,13 @@ gpkg_create_contents(x, query_string = FALSE) \item{table_name}{Name of table to add or remove record for in \emph{gpkg_contents}} -\item{description}{Default \code{""}} +\item{description}{Default: \code{""}} -\item{template}{Default \code{NULL} uses global EPSG:4326 with bounds -180,-90:180,90} +\item{srs_id}{\emph{integer}. Spatial Reference System ID. Must be defined in \code{gpkg_spatial_ref_sys} table.} + +\item{ext}{\emph{numeric}. A numeric vector of length four specifying the bounding box extent.} + +\item{template}{Deprecated. A list containing elements \code{"srsid"} and \code{"ext"}.} \item{query_string}{\emph{logical}. Return SQLite statement rather than executing it? Default: \code{FALSE}} }