Skip to content

Commit

Permalink
gpkg 0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
brownag committed Nov 21, 2023
1 parent e7fe1f9 commit 7c536b9
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 50 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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 <brown.andrewg@gmail.com>
Description: Functions to build Open Geospatial Consortium 'GeoPackage' files (<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.
Description: Build Open Geospatial Consortium 'GeoPackage' files (<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.
URL: https://humus.rocks/gpkg/, https://github.com/brownag/gpkg
BugReports: https://github.com/brownag/gpkg/issues
Imports:
Expand Down
13 changes: 9 additions & 4 deletions R/gpkg-extensions.R
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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) {

Expand Down
1 change: 1 addition & 0 deletions R/gpkg-sqlite.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/gpkg_bbox.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
76 changes: 48 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -133,7 +139,7 @@ g
#> rtree_bbox_geom_parent, rtree_bbox_geom_rowid, sqlite_sequence
#> --------------------------------------------------------------------------------
#> <SQLiteConnection>
#> Path: /tmp/RtmpQn6rEk/file1dace273bcd3c.gpkg
#> Path: /tmp/RtmpQZ3zKV/file304b339abcc96.gpkg
#> Extensions: TRUE
class(g)
#> [1] "geopackage"
Expand All @@ -157,14 +163,14 @@ g2
#> rtree_bbox_geom_parent, rtree_bbox_geom_rowid, sqlite_sequence
#> --------------------------------------------------------------------------------
#> <SQLiteConnection>
#> 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(<list>)` constructor.

You also may have a *DBIConnection* to a GeoPackage database already
Expand Down Expand Up @@ -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
Expand All @@ -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<myattr> [10 x 2]
#> # Database: sqlite 3.41.2 [/tmp/RtmpQn6rEk/file1dace273bcd3c.gpkg]
#> # Database: sqlite 3.41.2 [/tmp/RtmpQZ3zKV/file304b339abcc96.gpkg]
#> a b
#> <int> <chr>
#> 1 1 A
Expand All @@ -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)

Expand Down Expand Up @@ -287,13 +293,13 @@ returns a *tbl_SQLiteConnection*.
``` r
gpkg_tbl(g, "gpkg_contents")
#> # Source: table<gpkg_contents> [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
#> <chr> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
#> 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 <dbl>, srs_id <int>
```

Expand All @@ -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 <NA>
#> 2 zoom_level INTEGER 1 <NA>
Expand Down Expand Up @@ -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)
```

Expand All @@ -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 : <chr> <int>
Expand Down Expand Up @@ -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
Expand All @@ -438,13 +444,13 @@ contains critical information on the data contained in a GeoPackage.
``` r
gpkg_table(g, "gpkg_contents")
#> # Source: table<gpkg_contents> [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
#> <chr> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
#> 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 <dbl>, srs_id <int>
```

Expand Down Expand Up @@ -484,7 +490,21 @@ gpkg_is_connected(g)
gpkg_disconnect(g)

# reconnect
g <- gpkg_connect(g)
gpkg_connect(g)
#> <geopackage>
#> --------------------------------------------------------------------------------
#> # 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
#> --------------------------------------------------------------------------------
#> <SQLiteConnection>
#> Path: /tmp/RtmpQZ3zKV/file304b339abcc96.gpkg
#> Extensions: TRUE

# disconnect
gpkg_disconnect(g)
Expand Down
6 changes: 0 additions & 6 deletions cran-comments.md

This file was deleted.

4 changes: 0 additions & 4 deletions inst/tinytest/test_gpkg.R
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion man/gpkg-package.Rd

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

7 changes: 5 additions & 2 deletions man/gpkg_add_metadata_extension.Rd

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

7 changes: 5 additions & 2 deletions man/gpkg_add_relatedtables_extension.Rd

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

2 changes: 1 addition & 1 deletion man/gpkg_bbox.Rd

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

3 changes: 3 additions & 0 deletions man/gpkg_update_table.Rd

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

0 comments on commit 7c536b9

Please sign in to comment.