gpkg_table_pragma {gpkg}R Documentation

Lazy Access to Tables by Name

Description

gpkg_table_pragma(): Get information on a table in a GeoPackage (without returning the whole table).

gpkg_table(): access a specific table (by name) and get a "lazy" tibble object referencing that table

gpkg_collect(): alias for gpkg_table(..., collect=TRUE)

gpkg_tbl(): shorthand for gpkg_table(..., collect=FALSE)(default) that always returns a 'dplyr' object.

Usage

gpkg_table_pragma(x, table_name = NULL, ...)

## S3 method for class 'character'
gpkg_table_pragma(x, table_name = NULL, ...)

## S3 method for class 'SQLiteConnection'
gpkg_table_pragma(x, table_name, ...)

## S3 method for class 'geopackage'
gpkg_table_pragma(x, table_name = NULL, ...)

gpkg_table(x, table_name, collect = FALSE, query_string = FALSE, ...)

## Default S3 method:
gpkg_table(x, table_name, collect = FALSE, query_string = FALSE, ...)

gpkg_collect(x, table_name, query_string = FALSE, ...)

gpkg_tbl(x, table_name, ...)

gpkg_rast(x, table_name = NULL, ...)

gpkg_vect(x, table_name, ...)

Arguments

x

A geopackage object or character path to GeoPackage file

table_name

character. One or more table names; for gpkg_table_pragma() if table_name=NULL returns a record for each table. gpkg_table() requires table_name be specified

...

Additional arguments. In gpkg_table() arguments in ... are passed to dplyr::tbl(). For gpkg_table_pragma(), ... arguments are (currently) not used. For gpkg_rast() additional arguments are passed to terra::rast(). For gpkg_vect() additional arguments (such as proxy=TRUE) are passed to terra::vect().

collect

logical. Materialize a data.frame object in memory? Default: FALSE requires 'dbplyr' package. TRUE uses 'RSQLite'.

query_string

logical. Return SQLite query rather than executing it? Default: FALSE

Value

gpkg_table(): A 'dbplyr' object of class tbl_SQLiteConnection

gpkg_collect(): An object of class data.frame

gpkg_tbl(): An object of class tbl_SQLiteConnection

gpkg_rast(): A 'terra' object of class SpatRaster

gpkg_vect(): A 'terra' object of class SpatVector (may not contain geometry columns)

Examples




tf <- tempfile(fileext = ".gpkg")

r <- terra::rast(system.file("extdata", "dem.tif", package = "gpkg"))

gpkg_write(r,
           destfile = tf,
           RASTER_TABLE = "DEM1",
           FIELD_NAME = "Elevation")

gpkg_write(r,
           destfile = tf,
           append = TRUE,
           RASTER_TABLE = "DEM2",
           FIELD_NAME = "Elevation")

g <- geopackage(tf)

# inspect gpkg_contents table
gpkg_table(g, "gpkg_contents")

gpkg_vect(g, "gpkg_contents")

# materialize a data.frame from gpkg_2d_gridded_tile_ancillary
library(dplyr, warn.conflicts = FALSE)

gpkg_table(g, "gpkg_2d_gridded_tile_ancillary") %>% 
  dplyr::filter(tpudt_name == "DEM2") %>% 
  dplyr::select(mean, std_dev) %>% 
  dplyr::collect()

gpkg_disconnect(g)

[Package gpkg version 0.0.8 Index]