| Title: | Utilities for the Open Geospatial Consortium 'GeoPackage' Format |
|---|---|
| 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. |
| Authors: | Andrew Brown [aut, cre] (ORCID: <https://orcid.org/0000-0002-4565-533X>) |
| Maintainer: | Andrew Brown <[email protected]> |
| License: | CC0 |
| Version: | 0.0.14 |
| Built: | 2026-05-23 08:06:47 UTC |
| Source: | https://github.com/brownag/gpkg |
geopackage Constructorsgeopackage() (alias gpkg()) creates an S3 object of class geopackage.
geopackage(x, ...) ## S3 method for class 'list' geopackage(x, dsn = NULL, connect = FALSE, ...) ## S3 method for class 'missing' geopackage(x, connect = FALSE, pattern = "Rgpkg", tmpdir = tempdir(), ...) ## S3 method for class 'SQLiteConnection' geopackage(x, connect = FALSE, ...) ## S3 method for class 'geopackage' geopackage(x, ...) ## S3 method for class 'character' geopackage(x, connect = FALSE, ...) gpkg(x, ...)geopackage(x, ...) ## S3 method for class 'list' geopackage(x, dsn = NULL, connect = FALSE, ...) ## S3 method for class 'missing' geopackage(x, connect = FALSE, pattern = "Rgpkg", tmpdir = tempdir(), ...) ## S3 method for class 'SQLiteConnection' geopackage(x, connect = FALSE, ...) ## S3 method for class 'geopackage' geopackage(x, ...) ## S3 method for class 'character' geopackage(x, connect = FALSE, ...) gpkg(x, ...)
x |
list of SpatVectorProxy, SpatRaster, data.frame; or a character containing path to a GeoPackage file; or an SQLiteConnection to a GeoPackage. If missing, a temporary file with .gpkg extension is created in |
... |
Additional arguments [not currently used] |
dsn |
Path to GeoPackage File (may not exist) |
connect |
Connect to database and store connection in result? Default: |
pattern |
used only when |
tmpdir |
used only when |
Several geopackage() methods are provided:
geopackage(x=<list>): creates a new GeoPackage object from a heterogeneous list of inputs
geopackage(x=<missing>): creates a new empty GeoPackage file in tmpdir
geopackage(x=<SQLiteConnection>): creates a GeoPackage object from an existing SQLite connection
geopackage(x=<character>): creates a GeoPackage object from a path to an existing GeoPackage file
A geopackage object
gpkg_2d_gridded_coverage_ancillary TableGet gpkg_2d_gridded_coverage_ancillary Table
gpkg_2d_gridded_coverage_ancillary(x)gpkg_2d_gridded_coverage_ancillary(x)
x |
A geopackage object, path to a GeoPackage or an SQLiteConnection |
a data.frame containing columns id, tile_matrix_set_name, datatype, scale, offset, precision, data_null, grid_cell_encoding, uom, field_name, quantity_definition
gpkg_2d_gridded_tile_ancillary TableGet gpkg_2d_gridded_tile_ancillary Table
gpkg_2d_gridded_tile_ancillary(x)gpkg_2d_gridded_tile_ancillary(x)
x |
A geopackage object, path to a GeoPackage or an SQLiteConnection |
a data.frame containing columns id, tile_matrix_set_name, datatype, scale, offset, precision, data_null, grid_cell_encoding, uom, field_name, quantity_definition
gpkg_contents table and recordsgpkg_add_contents(): Add a record to gpkg_contents
gpkg_update_contents(): Add and remove gpkg_contents records to match existing tables
gpkg_delete_contents(): Delete a record from gpkg_contents based on table name
gpkg_create_contents(): Create an empty gpkg_contents table
gpkg_add_contents( x, table_name, data_type = NULL, description = "", srs_id = NULL, ext = NULL, template = NULL, query_string = FALSE ) gpkg_update_contents(x) gpkg_delete_contents(x, table_name, query_string = FALSE) gpkg_create_contents(x, query_string = FALSE)gpkg_add_contents( x, table_name, data_type = NULL, description = "", srs_id = NULL, ext = NULL, template = NULL, query_string = FALSE ) gpkg_update_contents(x) gpkg_delete_contents(x, table_name, query_string = FALSE) gpkg_create_contents(x, query_string = FALSE)
x |
A geopackage |
table_name |
Name of table to add or remove record for in gpkg_contents |
data_type |
character. One of: |
description |
Default: |
srs_id |
integer. Spatial Reference System ID. Must be defined in |
ext |
numeric. A numeric vector of length four specifying the bounding box extent. |
template |
Deprecated. A list containing elements |
query_string |
logical. Return SQLite statement rather than executing it? Default: |
logical. TRUE on successful execution of SQL statements.
Adds the "Metadata" extension tables.
gpkg_add_metadata_extension(x)gpkg_add_metadata_extension(x)
x |
a |
0 (invisible). Called for side effects.
Method for creating and connecting SQLiteConnection object stored within geopackage object.
gpkg_connect(x) ## S3 method for class 'geopackage' gpkg_connect(x) ## S3 method for class 'character' gpkg_connect(x) gpkg_is_connected(x) ## S3 method for class 'geopackage' gpkg_is_connected(x) gpkg_disconnect(x) ## S3 method for class 'geopackage' gpkg_disconnect(x) ## S3 method for class 'SQLiteConnection' gpkg_disconnect(x) ## S3 method for class 'tbl_SQLiteConnection' gpkg_disconnect(x) ## S3 method for class 'src_SQLiteConnection' gpkg_disconnect(x) gpkg_connection(x, disconnect = FALSE) ## Default S3 method: gpkg_connection(x, disconnect = FALSE)gpkg_connect(x) ## S3 method for class 'geopackage' gpkg_connect(x) ## S3 method for class 'character' gpkg_connect(x) gpkg_is_connected(x) ## S3 method for class 'geopackage' gpkg_is_connected(x) gpkg_disconnect(x) ## S3 method for class 'geopackage' gpkg_disconnect(x) ## S3 method for class 'SQLiteConnection' gpkg_disconnect(x) ## S3 method for class 'tbl_SQLiteConnection' gpkg_disconnect(x) ## S3 method for class 'src_SQLiteConnection' gpkg_disconnect(x) gpkg_connection(x, disconnect = FALSE) ## Default S3 method: gpkg_connection(x, disconnect = FALSE)
x |
A geopackage or SQLiteConnection object |
disconnect |
Set attribute |
The S3 method for geopackage objects does not require the use of assignment to create an object containing an active SQLiteConnection. e.g. gpkg_connect(g) connects the existing geopackage object g
A DBIConnection (SQLiteConnection) object. NULL on error.
If x is geopackage, the disconnected object is returned. If x is a SQLiteConnection, logical (TRUE if successfully disconnected).
gpkg_contents or gpkg_ogr_contents TableThese functions provide convenient access to the contents of the standard GeoPackage tables of the same name.
gpkg_contents(x, create = FALSE) gpkg_ogr_contents(x)gpkg_contents(x, create = FALSE) gpkg_ogr_contents(x)
x |
A geopackage object, path to a GeoPackage or an SQLiteConnection |
create |
Create table |
gpkg_contents(): a data.frame containing columns table_name, data_type, identifier, description, last_change, min_x, min_y, max_x, max_y, srs_id
gpkg_ogr_contents(): a data.frame containing columns table_name and feature_count.
Create 2D Gridded Coverage and Tile Ancillary Tables
gpkg_create_2d_gridded_coverage_ancillary(x) gpkg_create_2d_gridded_tile_ancillary(x)gpkg_create_2d_gridded_coverage_ancillary(x) gpkg_create_2d_gridded_tile_ancillary(x)
x |
A geopackage object |
gpkg_create_2d_gridded_coverage_ancillary(): integer. Result of running sequential gpkg_execute() statements.
gpkg_create_2d_gridded_tile_ancillary(): integer. Result of running sequential gpkg_execute() statements.
http://www.opengis.net/doc/IS/geopackage-gr/1.0
This function has been deprecated. Please use gpkg_create_empty_features().
gpkg_create_dummy_features(x, table_name = "dummy_feature", values = NULL)gpkg_create_dummy_features(x, table_name = "dummy_feature", values = NULL)
x |
A geopackage object |
table_name |
A table name; default |
values |
Values to use for new table. Defaults to default geometry name ( |
Create a minimal (empty) feature table and gpkg_geometry_columns table entry.
This is a workaround so that gpkg_vect() (via terra::vect()) will recognize a GeoPackage as containing geometries and allow for use of OGR query utilities. The "dummy table" is not added to gpkg_contents and you should not try to use it for anything. The main purpose is to be able to use gpkg_vect() and gpkg_ogr_query() on a GeoPackage that contains only gridded and/or attribute data.
logical. TRUE on success.
gpkg_create_empty_features() gpkg_vect() gpkg_ogr_query()
Create an empty feature table and associated entries for gpkg_spatial_ref_sys, and gpkg_geometry_columns.
gpkg_create_empty_features( x, table_name, column_name = "geom", geometry_type_name = "GEOMETRY", srs_id = 4326, z = 0L, m = 0L, contents = TRUE, description = "", ext = c(-180, -90, 180, 90) )gpkg_create_empty_features( x, table_name, column_name = "geom", geometry_type_name = "GEOMETRY", srs_id = 4326, z = 0L, m = 0L, contents = TRUE, description = "", ext = c(-180, -90, 180, 90) )
x |
A |
table_name |
character. New table name. |
column_name |
character. Geometry column name. Default |
geometry_type_name |
character. Geometry type name. Default: |
srs_id |
integer. Spatial Reference System ID. Must be defined in |
z |
integer. Default: |
m |
integer. Default: |
contents |
logical. If |
description |
character. Description for |
ext |
numeric. A numeric vector of length four specifying the bounding box extent. |
integer result of gpkg_execute(). Returns 1 if a new geometry record is appended to gpkg_geometry_columns table.
Create an empty grid table and associated entries for gpkg_spatial_ref_sys, gpkg_2d_gridded_coverage_ancillary, and gpkg_2d_gridded_tile_ancillary.
gpkg_create_empty_grid( x, tile_matrix_set_name, datatype = "integer", scale = 1, offset = 0, precision = 1, data_null = NULL, grid_cell_encoding = "grid-value-is-center", uom = NULL, field_name = "Height", quantity_definition = "Height", srs_id = 4326, contents = TRUE, description = "", ext = c(-180, -90, 180, 90) )gpkg_create_empty_grid( x, tile_matrix_set_name, datatype = "integer", scale = 1, offset = 0, precision = 1, data_null = NULL, grid_cell_encoding = "grid-value-is-center", uom = NULL, field_name = "Height", quantity_definition = "Height", srs_id = 4326, contents = TRUE, description = "", ext = c(-180, -90, 180, 90) )
x |
A geopackage object |
tile_matrix_set_name |
character. New table name. |
datatype |
character. Either |
scale |
numeric. Default: |
offset |
numeric. Default: |
precision |
numeric. Default: |
data_null |
numeric. Default: |
grid_cell_encoding |
character Default: |
uom |
character. Unit of measure. Default: |
field_name |
character. Default: |
quantity_definition |
character. Default: |
srs_id |
integer. Spatial Reference System ID. Must be defined in |
contents |
logical. Include entry in |
description |
character. Description for |
ext |
numeric. Length 4. Extent ( |
integer
Create gpkg_geometry_columns table to account for geometry columns within the database with gpkg_create_geometry_columns(). Register new geometry columns with gpkg_add_geometry_columns().
gpkg_create_geometry_columns(x) gpkg_add_geometry_columns( x, table_name, column_name, geometry_type_name = "GEOMETRY", srs_id, z, m )gpkg_create_geometry_columns(x) gpkg_add_geometry_columns( x, table_name, column_name, geometry_type_name = "GEOMETRY", srs_id, z, m )
x |
A geopackage object, or path to GeoPackage file. |
table_name |
character. New table name. |
column_name |
character. Geometry column name. Default |
geometry_type_name |
character. Geometry type name. Default: |
srs_id |
integer. Spatial Reference System ID. Must be defined in |
z |
integer. Default: |
m |
integer. Default: |
integer. 1 if table created or row inserted successfully, 0 otherwise.
Create a Spatial View
gpkg_create_spatial_view( g, viewname, viewquery, geom_column = "geom", geometry_type_name = "GEOMETRY", spatialite_computed = FALSE, data_type = "features", srs_id = 4326, z = 0, m = 0 )gpkg_create_spatial_view( g, viewname, viewquery, geom_column = "geom", geometry_type_name = "GEOMETRY", spatialite_computed = FALSE, data_type = "features", srs_id = 4326, z = 0, m = 0 )
g |
a |
viewname |
character. Name of view. |
viewquery |
character. Query for view contents. |
geom_column |
character. Column name of view geometry. Default: |
geometry_type_name |
character. View geometry type. Default: |
spatialite_computed |
logical. Register definition of |
data_type |
character. View data type. Default |
srs_id |
integer. Spatial Reference System ID. Default: |
z |
integer. Default: |
m |
integer. Default: |
integer. Returns 1 if a new record in gpkg_geometry_columns is successfully made.
GeoPackage Creation Options
gpkg_creation_optionsgpkg_creation_options
An object of class data.frame with 32 rows and 4 columns.
GDAL - GPKG – GeoPackage raster, GDAL - GPKG – GeoPackage vector
Returns a default NoData value for a given raster datatype, following GDAL
and terra conventions, and avoiding NaN values which produce a warning when
passed as data_null to GDAL. NOTE: at this time (GDAL 3.12) only Byte
(INT1U), Int16 (INT2S), UInt16 (INT2U) or Float32 (INT4S) datatypes are
supported in the GPKG raster driver.
gpkg_default_nodata(datatype)gpkg_default_nodata(datatype)
datatype |
character. A raster datatype code in terra format. Supported types are:
|
While NaN is technically a valid value for grids stored in a
geopackage, it is generally prefered to use a numeric value, as NaN is not
supported by SQLite 3 and is stored in the metadata column as SQL NULL.
These defaults are used by gpkg_write() when auto_nodata = TRUE.
For signed integer types, the minimum representable value (e.g., INT32_MIN) is returned, as it is unlikely to occur in valid data. For unsigned integer types, the maximum representable value is returned (e.g., UINT16_MAX), with the exception of INT1U (byte) which returns 255 (following terra convention). For float types, the negative extreme value is returned, as GeoPackage metadata cannot represent NaN.
| Datatype | Default NoData |
| INT1S | -128 |
| INT2S | -32768 |
| INT4S | -2147483648 |
| INT8S | -9223372036854775808 |
| INT1U | 255 |
| INT2U | 65534 |
| INT4U | 4294967295 |
| INT8U | 18446744073709549568 |
| FLT4S | -3.40282346638528860e+38 |
| FLT8S | -1.79769313486231571e+308 |
Note: The INT8U default (18446744073709549568) is UINT64_MAX - 1101 to
account for floating-point precision loss when converting to double,
following terra's convention. R does not have a native unsigned 64-bit
integer type.
numeric. The default NoData value for the given datatype, or
NA_real_ if no default is available or the datatype is not recognized.
gpkg_write() for using these defaults when writing rasters to
GeoPackage
gpkg_default_nodata("FLT4S") gpkg_default_nodata("INT2S") gpkg_default_nodata("INT2U")gpkg_default_nodata("FLT4S") gpkg_default_nodata("INT2S") gpkg_default_nodata("INT2U")
Execute an SQL statement in a GeoPackage
gpkg_execute(x, statement, ..., silent = FALSE)gpkg_execute(x, statement, ..., silent = FALSE)
x |
A geopackage object |
statement |
An SQLite statement |
... |
Additional arguments to |
silent |
Used to suppress error messages, passed to |
Invisible result of RSQLite::dbExecute(); or try-error on error.
Get Geopackage Extensions
gpkg_extensions(x)gpkg_extensions(x)
x |
A |
a data.frame
gpkg_contents
Get a vector of grid, feature and attribute table names registered in GeoPackage.
gpkg_list_contents(x, ogr = FALSE)gpkg_list_contents(x, ogr = FALSE)
x |
A geopackage object, path to a GeoPackage or an SQLiteConnection |
ogr |
Intersect |
character. Vector of grid, feature and attribute table names registered in GeoPackage.
gpkg_contents() gpkg_list_tables()
List Tables in a GeoPackage
gpkg_list_tables(x)gpkg_list_tables(x)
x |
A geopackage object, path to a GeoPackage or an SQLiteConnection |
a character vector with names of all tables and views in the database
gpkg_ogr_query(): an alias for gpkg_query(..., ogr=TRUE)
gpkg_query(x, query, ogr = FALSE, ...) gpkg_ogr_query(x, query, ...)gpkg_query(x, query, ogr = FALSE, ...) gpkg_ogr_query(x, query, ...)
x |
A geopackage object |
query |
character. An SQLite/Spatialite/GeoPackage query. The |
ogr |
logical. Use the OGR query interface (via |
... |
Additional arguments to |
The GeoPackage driver supports OGR attribute filters. Provide filters in the SQLite dialect, as they will be executed directly against the database. If Spatialite is used, a recent version (4.2.0) is needed and cast operators are required to transform GeoPackage geometries to Spatialite geometries. A variety of SQL functions are available, see: < https://gdal.org/en/stable/drivers/vector/gpkg.html#sql-functions>
a data.frame result of RSQLite::dbGetQuery() or SpatVector
result from terra::query().
This function creates a geopackage object with references to all tables
from the GeoPackage source specified in x. For a simple list of tables see
gpkg_tables().
gpkg_read(x, connect = FALSE, quiet = TRUE)gpkg_read(x, connect = FALSE, quiet = TRUE)
x |
Path to GeoPackage |
connect |
Connect to database and store connection in result? Default:
|
quiet |
Hide printing of gdalinfo description to stdout. Default: |
A geopackage object (list containing tables, grids and vector data)
Get Source File of a geopackage object
gpkg_source(x) ## S3 method for class 'geopackage' gpkg_source(x)gpkg_source(x) ## S3 method for class 'geopackage' gpkg_source(x)
x |
A geopackage object |
character file path
GeoPackage Spatial Reference System
gpkg_spatial_ref_sys(x) gpkg_list_srs(x, column_name = "srs_id") gpkg_create_spatial_ref_sys(x, default = TRUE, query_string = FALSE) gpkg_add_spatial_ref_sys( x, srs_name = "", srs_id = NULL, organization = "", organization_coordsys_id = 0L, definition = "", description = "", query_string = FALSE ) gpkg_delete_spatial_ref_sys(x, srs_id = NULL)gpkg_spatial_ref_sys(x) gpkg_list_srs(x, column_name = "srs_id") gpkg_create_spatial_ref_sys(x, default = TRUE, query_string = FALSE) gpkg_add_spatial_ref_sys( x, srs_name = "", srs_id = NULL, organization = "", organization_coordsys_id = 0L, definition = "", description = "", query_string = FALSE ) gpkg_delete_spatial_ref_sys(x, srs_id = NULL)
x |
A geopackage object |
column_name |
Default: |
default |
logical or character. If |
query_string |
logical. Return SQL queries without executing? Default: |
srs_name |
character. Spatial Reference System Name, for example |
srs_id |
integer. Spatial Reference System ID, for example |
organization |
character. Organization, for example |
organization_coordsys_id |
integer. Organization Coordinate System ID, for example |
definition |
character. WKT2019 Coordinate Reference System description string |
description |
character. Description |
gpkg_spatial_ref_sys(): data.frame
gpkg_list_srs(): vector of values from specified column_name
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.
gpkg_add_spatial_ref_sys(): integer result of executing SQL statement
gpkg_delete_spatial_ref_sys(): integer result of executing SQL statement
GeoPackage Dataset
GeoPackage SQLite Tables
gpkg_sqlite_tablesgpkg_sqlite_tables
a data.frame with 1 column ("table_name") and 10 rows
GDAL - GPKG – GeoPackage raster, GDAL - GPKG – GeoPackage vector
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 tbl_SQLiteConnection object referencing that table
gpkg_collect(): Alias for gpkg_table(..., collect=TRUE)
gpkg_tbl(): Alias for gpkg_table(..., collect=FALSE)(default) that always returns a tbl_SQLiteConnection object.
gpkg_rast(): Get a SpatRaster object corresponding to the specified table_name
gpkg_vect(): Get a SpatVector object corresponding to the specified table_name
gpkg_sf(): Get a sf-tibble object corresponding to the specified table_name
gpkg_table_pragma(x, table_name = NULL, ...) ## Default S3 method: gpkg_table_pragma(x, table_name = NULL, ...) gpkg_table( x, table_name, collect = FALSE, column_names = "*", query_string = FALSE, ... ) ## Default S3 method: gpkg_table( x, table_name, collect = FALSE, column_names = "*", 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, ...) gpkg_sf(x, table_name, ...)gpkg_table_pragma(x, table_name = NULL, ...) ## Default S3 method: gpkg_table_pragma(x, table_name = NULL, ...) gpkg_table( x, table_name, collect = FALSE, column_names = "*", query_string = FALSE, ... ) ## Default S3 method: gpkg_table( x, table_name, collect = FALSE, column_names = "*", 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, ...) gpkg_sf(x, table_name, ...)
x |
A geopackage object or character path to GeoPackage file |
table_name |
character. One or more table names; for |
... |
Additional arguments. In |
collect |
logical. Materialize a data.frame object in memory? Default: |
column_names |
character. Used only when |
query_string |
logical. Return SQLite query rather than executing it? Default: |
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)
gpkg_sf()): An sf-tibble object of class "sf", "tbl_df". If the table contains no geometry column the result is a "tbl_df".
tf <- tempfile(fileext = ".gpkg") r <- terra::rast(system.file("extdata", "dem.tif", package = "gpkg")) gpkg_write(r, tf, RASTER_TABLE = "DEM1", FIELD_NAME = "Elevation") gpkg_write(r, tf, append = TRUE, RASTER_TABLE = "DEM2", FIELD_NAME = "Elevation") g <- geopackage(tf, connect = TRUE) # inspect gpkg_contents table gpkg_table(g, "gpkg_contents") gpkg_contents(g) # 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)tf <- tempfile(fileext = ".gpkg") r <- terra::rast(system.file("extdata", "dem.tif", package = "gpkg")) gpkg_write(r, tf, RASTER_TABLE = "DEM1", FIELD_NAME = "Elevation") gpkg_write(r, tf, append = TRUE, RASTER_TABLE = "DEM2", FIELD_NAME = "Elevation") g <- geopackage(tf, connect = TRUE) # inspect gpkg_contents table gpkg_table(g, "gpkg_contents") gpkg_contents(g) # 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)
Get Tables from a geopackage object
gpkg_tables(x, collect = TRUE, pragma = TRUE) ## Default S3 method: gpkg_tables(x, collect = TRUE, pragma = TRUE)gpkg_tables(x, collect = TRUE, pragma = TRUE) ## Default S3 method: gpkg_tables(x, collect = TRUE, pragma = TRUE)
x |
A geopackage object |
collect |
Default: |
pragma |
Default: |
a list of SpatVectorProxy, SpatRaster, data.frame (lazy tbl?)
data_null Metadata for a GeoPackage Tile DatasetSet data_null Metadata for a GeoPackage Tile Dataset
gpkg_tile_set_data_null(x, name, value, query_string = FALSE)gpkg_tile_set_data_null(x, name, value, query_string = FALSE)
x |
A geopackage object, path to a GeoPackage or an SQLiteConnection |
name |
character. Tile matrix set name(s) ( |
value |
numeric. Value to use as "NoData" ( |
query_string |
logical. Return SQLite query rather than executing it? Default: |
logical. TRUE if number of data_null records updated is greater than 0.
For a given table, set column updatecol to scalar updatevalue where column wherecol is in vector wherevector.
gpkg_update_table( x, table_name, updatecol, updatevalue, wherecol = NULL, wherevector = NULL, query_string = FALSE )gpkg_update_table( x, table_name, updatecol, updatevalue, wherecol = NULL, wherevector = NULL, query_string = FALSE )
x |
A geopackage object, path to a GeoPackage or an SQLiteConnection. |
table_name |
character. Table name. |
updatecol |
character. Column to update. |
updatevalue |
character, numeric, etc.; A scalar value to set. |
wherecol |
character. Column used to constrain update. |
wherevector |
character, numeric, etc.; Vector of values where update should be made. |
query_string |
logical. Return SQLite query rather than executing it? Default: |
integer. Number of rows updated by executing UPDATE query. Or character SQL query string if query_string=TRUE.
Checks for presence of required tables, valid values and other constraints.
gpkg_validate(x, diagnostics = FALSE)gpkg_validate(x, diagnostics = FALSE)
x |
A geopackage object, or character path to GeoPackage |
diagnostics |
Return a list containing individual diagnostic test results (see 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
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.
Write data to a GeoPackage
gpkg_write( x, y = NULL, table_name = NULL, datatype = "FLT4S", append = FALSE, overwrite = FALSE, NoData = NULL, gdal_options = NULL, auto_nodata = TRUE, destfile = NULL, ... )gpkg_write( x, y = NULL, table_name = NULL, datatype = "FLT4S", append = FALSE, overwrite = FALSE, NoData = NULL, gdal_options = NULL, auto_nodata = TRUE, destfile = NULL, ... )
x |
Vector of source file path(s), or a list containing one or more SpatRaster, SpatRasterCollection, SpatVectorProxy, or data.frame objects. |
y |
character, geopackage, or DBIConnection. |
table_name |
character. Default |
datatype |
character. Data type. Defaults to |
append |
logical. Append to existing data source? Default: |
overwrite |
logical. Overwrite existing data source? Default |
NoData |
numeric. Value to use as GDAL |
gdal_options |
character. Additional |
auto_nodata |
logical. If TRUE (default), automatically select a datatype-appropriate
default NoData value when |
destfile |
character. Path to output GeoPackage |
... |
Additional arguments are passed as GeoPackage creation options. See Details. |
gpkg_write() can write multiple layers of different types (raster,
vector, and attributes) in a single call when x is a list. If calling
gpkg_write() multiple times to build a GeoPackage, use append=TRUE
to add additional layers. To replace a specific table while preserving
others, use overwrite=TRUE. Note that overwrite=TRUE only drops the
specified table_name and does not affect other tables in the file.
Additional, non-default GeoPackage creation options can be specified
as arguments to this function. The full list of creation options can be
viewed
here
or in the gpkg_creation_options dataset. The name of the argument is
creation_option and the value is selected from one of the elements of
values for that option.
If x contains source file paths, any comma-separated value (CSV) files
are treated as attribute data–even if they contain a geometry column.
GeoPackage source file paths are always treated as vector data sources, and
only one layer will be read from the source and written to the target. If
you need to read raster data from a GeoPackage first create a SpatRaster
from the layer of interest (see gpkg_rast()) before passing to
gpkg_write(). If you need to read multiple layers from any multi-layer
source read them individually into suitable objects. For a source
GeoPackage containing multiple layers you can use gpkg_read() (returns a
geopackage object) or gpkg_tables() (returns a list object).
Logical. TRUE on successful write of at least one grid.
gpkg_creation_options gpkg_default_nodata()
gpkg_write_attributes(): Specify a target geopackage and name for new table. For adding attributes, specify the new data as data.frame. The table name will be registered in the gpkg_contents table. Optionally include a custom description and/or use a template object to define the spatial extent associated with attribute data.
gpkg_remove_attributes(): Remove an attribute table and corresponding gpkg_contents record
gpkg_write_attributes( x, table, table_name, description = "", template = NULL, overwrite = FALSE, append = FALSE ) gpkg_remove_attributes(x, table_name)gpkg_write_attributes( x, table, table_name, description = "", template = NULL, overwrite = FALSE, append = FALSE ) gpkg_remove_attributes(x, table_name)
x |
A |
table |
A |
table_name |
|
description |
Optional description. Default |
template |
A |
overwrite |
Overwrite existing table? Default |
append |
Append rows to existing table? Default |
logical. TRUE on successful table write or remove.