diff --git a/DESCRIPTION b/DESCRIPTION index 44fc4f5..693978a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,7 +4,7 @@ Title: Utilities for the Open Geospatial Consortium 'GeoPackage' Format Version: 0.0.7 Authors@R: person(given="Andrew", family="Brown", email="brown.andrewg@gmail.com", role = c("aut", "cre")) Maintainer: Andrew Brown -Description: Functions to build Open Geospatial Consortium 'GeoPackage' files (). 'GDAL' utilities for read and write of spatial data are provided via the 'terra' package. Additional 'GeoPackage' and 'SQLite' specific functions manipulate attributes and tabular data via the 'RSQLite' package. +Description: Build Open Geospatial Consortium 'GeoPackage' files (). 'GDAL' utilities for reading and writing spatial data are provided by the 'terra' package. Additional 'GeoPackage' and 'SQLite' features for attributes and tabular data are implemented with the 'RSQLite' package. URL: https://humus.rocks/gpkg/, https://github.com/brownag/gpkg BugReports: https://github.com/brownag/gpkg/issues Imports: diff --git a/R/gpkg-extensions.R b/R/gpkg-extensions.R index d23214b..a9717d7 100644 --- a/R/gpkg-extensions.R +++ b/R/gpkg-extensions.R @@ -1,6 +1,9 @@ -#' Add Metadata extension +#' Add 'Metadata' extension +#' +#' Adds the "Metadata" extension tables. #' #' @param x a `geopackage` +#' @return `0` (invisible). Called for side effects. #' @export gpkg_add_metadata_extension <- function(x) { tbls <- gpkg_list_tables(x) @@ -37,13 +40,15 @@ gpkg_add_metadata_extension <- function(x) { CONSTRAINT crmr_mfi_fk FOREIGN KEY (md_file_id) REFERENCES gpkg_metadata(id), CONSTRAINT crmr_mpi_fk FOREIGN KEY (md_parent_id) REFERENCES gpkg_metadata(id) );") - - 0 + invisible(0) } -#' Add Related Tables extension +#' Add 'Related Tables' extension #' +#' Adds the "Related Tables" extension tables. +#' #' @param x a `geopackage` +#' @return `0` (invisible). Called for side effects. #' @export gpkg_add_relatedtables_extension <- function(x) { diff --git a/R/gpkg-sqlite.R b/R/gpkg-sqlite.R index 18cd23c..3695fc5 100644 --- a/R/gpkg-sqlite.R +++ b/R/gpkg-sqlite.R @@ -11,6 +11,7 @@ #' @param wherecol _character_. Column used to constrain update. #' @param wherevector _character_, _numeric_, etc.; Vector of values where update should be made. #' @param query_string _logical_. Return SQLite query rather than executing it? Default: `FALSE` +#' @return _integer_. Number of rows updated by executing `UPDATE` query. Or `character` SQL query string if `query_string=TRUE`. #' @export gpkg_update_table <- function(x, table_name, updatecol, updatevalue, diff --git a/R/gpkg_bbox.R b/R/gpkg_bbox.R index 4b19712..f6ac339 100644 --- a/R/gpkg_bbox.R +++ b/R/gpkg_bbox.R @@ -11,7 +11,7 @@ #' @export #' @examplesIf !inherits(try(requireNamespace("terra", quietly=TRUE), silent=TRUE), 'try-error') #' -#' \dontrun{ +#' \donttest{ #' tf <- tempfile(fileext = ".gpkg") #' #' r <- terra::rast(system.file("extdata", "dem.tif", package = "gpkg")) diff --git a/README.md b/README.md index 2bc51f0..8a2a106 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,13 @@ attributes and tabular data via the ## Installation -The package can be installed from GitHub with {remotes} +Install the latest release from CRAN: + +``` r +install.packages("gpkg") +``` + +The development package can be installed from GitHub with {remotes} ``` r if (!requireNamespace("remotes")) @@ -63,7 +69,7 @@ start by adding two DEM (GeoTIFF) files. ``` r library(gpkg) library(terra) -#> terra 1.7.60 +#> terra 1.7.55 dem <- system.file("extdata", "dem.tif", package = "gpkg") stopifnot(nchar(dem) > 0) @@ -133,7 +139,7 @@ g #> rtree_bbox_geom_parent, rtree_bbox_geom_rowid, sqlite_sequence #> -------------------------------------------------------------------------------- #> -#> Path: /tmp/RtmpQn6rEk/file1dace273bcd3c.gpkg +#> Path: /tmp/RtmpQZ3zKV/file304b339abcc96.gpkg #> Extensions: TRUE class(g) #> [1] "geopackage" @@ -157,14 +163,14 @@ g2 #> rtree_bbox_geom_parent, rtree_bbox_geom_rowid, sqlite_sequence #> -------------------------------------------------------------------------------- #> -#> Path: /tmp/RtmpQn6rEk/Rgpkg1dace68186eca.gpkg +#> Path: /tmp/RtmpQZ3zKV/Rgpkg304b329e168a3.gpkg #> Extensions: TRUE class(g2) #> [1] "geopackage" ``` Note that a temporary GeoPackage -(/tmp/RtmpQn6rEk/Rgpkg1dace68186eca.gpkg) is automatically created when +(/tmp/RtmpQZ3zKV/Rgpkg304b329e168a3.gpkg) is automatically created when using the `geopackage()` constructor. You also may have a *DBIConnection* to a GeoPackage database already @@ -203,8 +209,8 @@ gpkg_tables(g) #> resolution : 0.008333333, 0.008333333 (x, y) #> extent : 6.008333, 6.266667, 49.69167, 49.94167 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) -#> source : file1dace273bcd3c.gpkg:DEM1 -#> varname : file1dace273bcd3c +#> source : file304b339abcc96.gpkg:DEM1 +#> varname : file304b339abcc96 #> name : DEM1 #> min value : 195 #> max value : 500 @@ -215,15 +221,15 @@ gpkg_tables(g) #> resolution : 0.008333333, 0.008333333 (x, y) #> extent : 6.008333, 6.266667, 49.69167, 49.94167 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) -#> source : file1dace273bcd3c.gpkg:DEM2 -#> varname : file1dace273bcd3c +#> source : file304b339abcc96.gpkg:DEM2 +#> varname : file304b339abcc96 #> name : DEM2 #> min value : 195 #> max value : 500 #> #> $myattr #> # Source: table [10 x 2] -#> # Database: sqlite 3.41.2 [/tmp/RtmpQn6rEk/file1dace273bcd3c.gpkg] +#> # Database: sqlite 3.41.2 [/tmp/RtmpQZ3zKV/file304b339abcc96.gpkg] #> a b #> #> 1 1 A @@ -242,7 +248,7 @@ gpkg_tables(g) #> geometry : polygons #> dimensions : 1, 0 (geometries, attributes) #> extent : 6.008333, 6.266667, 49.69167, 49.94167 (xmin, xmax, ymin, ymax) -#> source : file1dace273bcd3c.gpkg (bbox) +#> source : file304b339abcc96.gpkg (bbox) #> layer : bbox #> coord. ref. : lon/lat WGS 84 (EPSG:4326) @@ -287,13 +293,13 @@ returns a *tbl_SQLiteConnection*. ``` r gpkg_tbl(g, "gpkg_contents") #> # Source: table [4 x 10] -#> # Database: sqlite 3.41.2 [/tmp/RtmpQn6rEk/file1dace273bcd3c.gpkg] +#> # Database: sqlite 3.41.2 [/tmp/RtmpQZ3zKV/file304b339abcc96.gpkg] #> table_name data_type identifier description last_change min_x min_y max_x #> #> 1 DEM1 2d-gridded… DEM1 "" 2023-11-19… 6.01 49.7 6.27 #> 2 DEM2 2d-gridded… DEM2 "" 2023-11-19… 6.01 49.7 6.27 #> 3 bbox features bbox "" 2023-11-19… 6.01 49.7 6.27 -#> 4 myattr attributes myattr "" 2023-11-18… -180 -90 180 +#> 4 myattr attributes myattr "" 2023-11-19… -180 -90 180 #> # ℹ 2 more variables: max_y , srs_id ``` @@ -316,12 +322,12 @@ analysis. ``` r head(gpkg_table_pragma(g)) #> dsn table_name nrow table_info.cid -#> 1 /tmp/RtmpQn6rEk/file1dace273bcd3c.gpkg DEM1 1 0 -#> 2 /tmp/RtmpQn6rEk/file1dace273bcd3c.gpkg DEM1 1 1 -#> 3 /tmp/RtmpQn6rEk/file1dace273bcd3c.gpkg DEM1 1 2 -#> 4 /tmp/RtmpQn6rEk/file1dace273bcd3c.gpkg DEM1 1 3 -#> 5 /tmp/RtmpQn6rEk/file1dace273bcd3c.gpkg DEM1 1 4 -#> 6 /tmp/RtmpQn6rEk/file1dace273bcd3c.gpkg DEM2 1 0 +#> 1 /tmp/RtmpQZ3zKV/file304b339abcc96.gpkg DEM1 1 0 +#> 2 /tmp/RtmpQZ3zKV/file304b339abcc96.gpkg DEM1 1 1 +#> 3 /tmp/RtmpQZ3zKV/file304b339abcc96.gpkg DEM1 1 2 +#> 4 /tmp/RtmpQZ3zKV/file304b339abcc96.gpkg DEM1 1 3 +#> 5 /tmp/RtmpQZ3zKV/file304b339abcc96.gpkg DEM1 1 4 +#> 6 /tmp/RtmpQZ3zKV/file304b339abcc96.gpkg DEM2 1 0 #> table_info.name table_info.type table_info.notnull table_info.dflt_value #> 1 id INTEGER 0 #> 2 zoom_level INTEGER 1 @@ -349,7 +355,7 @@ gpkg_vect(g, 'bbox') #> geometry : polygons #> dimensions : 1, 0 (geometries, attributes) #> extent : 6.008333, 6.266667, 49.69167, 49.94167 (xmin, xmax, ymin, ymax) -#> source : file1dace273bcd3c.gpkg (bbox) +#> source : file304b339abcc96.gpkg (bbox) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) ``` @@ -363,7 +369,7 @@ gpkg_vect(g, 'gpkg_ogr_contents') #> geometry : none #> dimensions : 0, 2 (geometries, attributes) #> extent : 0, 0, 0, 0 (xmin, xmax, ymin, ymax) -#> source : file1dace273bcd3c.gpkg (SELECT) +#> source : file304b339abcc96.gpkg (SELECT) #> coord. ref. : #> names : table_name feature_count #> type : @@ -413,10 +419,10 @@ gpkg_rast(g) #> resolution : 0.008333333, 0.008333333 (x, y) #> extent : 6.008333, 6.266667, 49.69167, 49.94167 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) -#> sources : file1dace273bcd3c.gpkg:DEM1 -#> file1dace273bcd3c.gpkg:DEM2 -#> varnames : file1dace273bcd3c -#> file1dace273bcd3c +#> sources : file304b339abcc96.gpkg:DEM1 +#> file304b339abcc96.gpkg:DEM2 +#> varnames : file304b339abcc96 +#> file304b339abcc96 #> names : DEM1, DEM2 #> min values : 195, 195 #> max values : 500, 500 @@ -438,13 +444,13 @@ contains critical information on the data contained in a GeoPackage. ``` r gpkg_table(g, "gpkg_contents") #> # Source: table [4 x 10] -#> # Database: sqlite 3.41.2 [/tmp/RtmpQn6rEk/file1dace273bcd3c.gpkg] +#> # Database: sqlite 3.41.2 [/tmp/RtmpQZ3zKV/file304b339abcc96.gpkg] #> table_name data_type identifier description last_change min_x min_y max_x #> #> 1 DEM1 2d-gridded… DEM1 "" 2023-11-19… 6.01 49.7 6.27 #> 2 DEM2 2d-gridded… DEM2 "" 2023-11-19… 6.01 49.7 6.27 #> 3 bbox features bbox "" 2023-11-19… 6.01 49.7 6.27 -#> 4 myattr attributes myattr "" 2023-11-18… -180 -90 180 +#> 4 myattr attributes myattr "" 2023-11-19… -180 -90 180 #> # ℹ 2 more variables: max_y , srs_id ``` @@ -484,7 +490,21 @@ gpkg_is_connected(g) gpkg_disconnect(g) # reconnect -g <- gpkg_connect(g) +gpkg_connect(g) +#> +#> -------------------------------------------------------------------------------- +#> # of Tables: 21 +#> +#> DEM1, DEM2, bbox, dummy_feature, gpkg_2d_gridded_coverage_ancillary, +#> gpkg_2d_gridded_tile_ancillary, gpkg_contents, gpkg_extensions, +#> gpkg_geometry_columns, gpkg_metadata, gpkg_metadata_reference, +#> gpkg_ogr_contents, gpkg_spatial_ref_sys, gpkg_tile_matrix, +#> gpkg_tile_matrix_set, myattr, rtree_bbox_geom, rtree_bbox_geom_node, +#> rtree_bbox_geom_parent, rtree_bbox_geom_rowid, sqlite_sequence +#> -------------------------------------------------------------------------------- +#> +#> Path: /tmp/RtmpQZ3zKV/file304b339abcc96.gpkg +#> Extensions: TRUE # disconnect gpkg_disconnect(g) diff --git a/cran-comments.md b/cran-comments.md deleted file mode 100644 index bc903e9..0000000 --- a/cran-comments.md +++ /dev/null @@ -1,6 +0,0 @@ -## R CMD check results - -0 errors | 0 warnings | 1 note - -* This is a new release. -* Geospatial is spelled correctly, OGC is the acronym of Open Geospatial Consortium diff --git a/inst/tinytest/test_gpkg.R b/inst/tinytest/test_gpkg.R index fc48037..24eebc6 100644 --- a/inst/tinytest/test_gpkg.R +++ b/inst/tinytest/test_gpkg.R @@ -1,7 +1,3 @@ -# cleanup -if (interactive()) - rm(list = ls()) - # RSQLite and terra used heavily in tests # d(b)plyr used conditionally if (requireNamespace("tinytest", quietly = TRUE)) library(tinytest) diff --git a/man/gpkg-package.Rd b/man/gpkg-package.Rd index fe4a0a1..2ae074a 100644 --- a/man/gpkg-package.Rd +++ b/man/gpkg-package.Rd @@ -6,7 +6,7 @@ \alias{gpkg-package} \title{gpkg: Utilities for the Open Geospatial Consortium 'GeoPackage' Format} \description{ -Functions to build Open Geospatial Consortium 'GeoPackage' files (\url{https://www.geopackage.org/}). 'GDAL' utilities for read and write of spatial data are provided via the 'terra' package. Additional 'GeoPackage' and 'SQLite' specific functions manipulate attributes and tabular data via the 'RSQLite' package. +Build Open Geospatial Consortium 'GeoPackage' files (\url{https://www.geopackage.org/}). 'GDAL' utilities for reading and writing spatial data are provided by the 'terra' package. Additional 'GeoPackage' and 'SQLite' features for attributes and tabular data are implemented with the 'RSQLite' package. } \seealso{ Useful links: diff --git a/man/gpkg_add_metadata_extension.Rd b/man/gpkg_add_metadata_extension.Rd index c533a97..34b4caa 100644 --- a/man/gpkg_add_metadata_extension.Rd +++ b/man/gpkg_add_metadata_extension.Rd @@ -2,13 +2,16 @@ % Please edit documentation in R/gpkg-extensions.R \name{gpkg_add_metadata_extension} \alias{gpkg_add_metadata_extension} -\title{Add Metadata extension} +\title{Add 'Metadata' extension} \usage{ gpkg_add_metadata_extension(x) } \arguments{ \item{x}{a \code{geopackage}} } +\value{ +\code{0} (invisible). Called for side effects. +} \description{ -Add Metadata extension +Adds the "Metadata" extension tables. } diff --git a/man/gpkg_add_relatedtables_extension.Rd b/man/gpkg_add_relatedtables_extension.Rd index d0b1c6f..091c6d6 100644 --- a/man/gpkg_add_relatedtables_extension.Rd +++ b/man/gpkg_add_relatedtables_extension.Rd @@ -2,13 +2,16 @@ % Please edit documentation in R/gpkg-extensions.R \name{gpkg_add_relatedtables_extension} \alias{gpkg_add_relatedtables_extension} -\title{Add Related Tables extension} +\title{Add 'Related Tables' extension} \usage{ gpkg_add_relatedtables_extension(x) } \arguments{ \item{x}{a \code{geopackage}} } +\value{ +\code{0} (invisible). Called for side effects. +} \description{ -Add Related Tables extension +Adds the "Related Tables" extension tables. } diff --git a/man/gpkg_bbox.Rd b/man/gpkg_bbox.Rd index 58cd0cf..b12643d 100644 --- a/man/gpkg_bbox.Rd +++ b/man/gpkg_bbox.Rd @@ -22,7 +22,7 @@ This function applies an OGR SQL query to obtain bounding coordinates of a table \examples{ \dontshow{if (!inherits(try(requireNamespace("terra", quietly=TRUE), silent=TRUE), 'try-error')) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -\dontrun{ +\donttest{ tf <- tempfile(fileext = ".gpkg") r <- terra::rast(system.file("extdata", "dem.tif", package = "gpkg")) diff --git a/man/gpkg_update_table.Rd b/man/gpkg_update_table.Rd index 7e6e6cf..ebd9967 100644 --- a/man/gpkg_update_table.Rd +++ b/man/gpkg_update_table.Rd @@ -29,6 +29,9 @@ gpkg_update_table( \item{query_string}{\emph{logical}. Return SQLite query rather than executing it? Default: \code{FALSE}} } +\value{ +\emph{integer}. Number of rows updated by executing \code{UPDATE} query. Or \code{character} SQL query string if \code{query_string=TRUE}. +} \description{ For a given table, set column \code{updatecol} to scalar \code{updatevalue} where column \code{wherecol} is in vector \code{wherevector}. }