Skip to content

Commit

Permalink
gpkg-srs/gpkg_validate docs/cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brownag committed Mar 3, 2024
1 parent 71f52f1 commit 3721a3d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
4 changes: 2 additions & 2 deletions R/gpkg-srs.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ gpkg_list_srs <- function(x, column_name = "srs_id") {
}

#' @param default _logical_ or _character_. If `TRUE`, or one or more of `"cartesian"`, `"geographic"`, or `"crs84"`, then these default Spatial Reference Systems are added.
#' @return `gpkg_list_srs()`: _vector_ of values from specified `column_name`
#' @return `gpkg_create_spatial_ref_sys()`: _integer_. Result of running sequential `gpkg_execute()` statements. This method is run for the side-effect of creating the table if needed, and adding any "default" records.
#' @export
#' @rdname gpkg-srs
gpkg_create_spatial_ref_sys <- function(x, default = TRUE, query_string = FALSE) {
Expand Down Expand Up @@ -114,7 +114,7 @@ gpkg_create_spatial_ref_sys <- function(x, default = TRUE, query_string = FALSE)
#' @param organization _character_. Organization, for example `"EPSG"`
#' @param organization_coordsys_id _integer_. Organization Coordinate System ID, for example `4326L`
#' @param definition _character_. WKT2019 Coordinate Reference System description string
#' @param description _character. Description
#' @param description _character_. Description
#' @param query_string _logical_. Return SQL queries without executing? Default: `FALSE`
#'
#' @return `gpkg_add_spatial_ref_sys()`: _integer_ result of executing SQL statement
Expand Down
19 changes: 11 additions & 8 deletions R/gpkg-validate.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@
#'
#' Checks for presence of required tables, valid values and other constraints.
#'
#' @param x Path to GeoPackages
#' @param diagnostics Return a list containing diagnostics (missing table names, invalid values, other errors)
#'
#' @return `TRUE` if valid. `FALSE` if one or more problems are found. For full diagnostics run with `diagnostics = TRUE` to return a list containing results for each input GeoPackage.
#' @param x A _geopackage_ object, or _character_ path to GeoPackage
#' @param diagnostics Return a list containing individual diagnostic test results (see Details)
#' @details
#' Several tests are run on the input GeoPackage, including:
#' - `required_tables`: _logical_. `TRUE` if `gpkg_contents` and `gpkg_spatial_ref_sys` tables exist
#' - `has_contents`: _logical_. `TRUE` if the number of rows in `gpkg_contents` table is greater than `0` and all tables listed in `gpkg_contents` are in the database
#' - `has_spatial_tables`: _logical_. `TRUE` if the number of tables in `gpkg_contents` with `data_type` `"features"` or `"2d-gridded-coverage"` is greater than `0`
#'
#' @return _logical_. `TRUE` if valid. `FALSE` if one or more problems are found. For full diagnostics run with `diagnostics = TRUE` to return a list containing results for each test run on the input GeoPackage.
#' @export
gpkg_validate <- function(x, diagnostics = FALSE) {
x <- .gpkg_connection_from_x(x)
lt <- gpkg_list_tables(x)
cg <- gpkg_contents(x)
res <- list(
required_tables = all(c("gpkg_contents","gpkg_spatial_ref_sys") %in% lt),
has_contents = (nrow(cg) > 0),
has_spatial_tables = all(cg$table_name %in% lt) &&
sum(cg$data_type %in%
c("features", "2d-gridded-coverage")) > 0
has_contents = (nrow(cg) > 0) && all(cg$table_name %in% lt),
has_spatial_tables = sum(cg$data_type %in% c("features", "2d-gridded-coverage")) > 0
)
if (is.null(diagnostics) ||
length(diagnostics) == 0 ||
Expand Down
4 changes: 2 additions & 2 deletions man/gpkg-srs.Rd

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

14 changes: 11 additions & 3 deletions man/gpkg_validate.Rd

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

0 comments on commit 3721a3d

Please sign in to comment.