-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- deprecate gpkg_create_dummy_features() - add gpkg_create_empty_features() - add gpkg_create_geometry_columns() - add gpkg_add_geometry_columns() - deprecate gpkg_contents(template=) column
- Loading branch information
Showing
9 changed files
with
210 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# gpkg feature tables | ||
|
||
#' Create an empty feature table | ||
#' | ||
#' Create an empty feature table and associated entries for `gpkg_spatial_ref_sys`, and `gpkg_geometry_columns`. | ||
#' | ||
#' @param x A `geopackage` Object | ||
#' @param table_name _character_. New table name. | ||
#' @param geometry_type_name _character_. Geometry type name. Default: `"GEOMETRY"` | ||
#' @param column_name _character_. Geometry column name. Default `"geom"` | ||
#' @param srs_id _integer_. Spatial Reference System ID. Must be defined in `gpkg_spatial_ref_sys` table. | ||
#' @param z _integer_. Default: `0` | ||
#' @param m _integer_. Default: `0` | ||
#' @param contents _logical_. If `TRUE` (default) add the new table to `gpkg_contents` table. | ||
#' @param description _character_. Description for `gpkg_contents` table. Default: `""` | ||
#' @param ext _numeric_. A numeric vector of length four specifying the bounding box extent. | ||
#' | ||
#' @return _integer_ result of `gpkg_execute()`. Returns `1` if a new geometry record is appended to `gpkg_geometry_columns` table. | ||
#' | ||
#' @export | ||
#' @rdname gpkg-features | ||
gpkg_create_empty_features <- function(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_contents(x) | ||
gpkg_create_spatial_ref_sys(x) | ||
gpkg_create_geometry_columns(x) | ||
|
||
res <- 0 | ||
if (!table_name %in% gpkg_list_tables(x)) { | ||
res <- gpkg_execute(x, paste0("CREATE TABLE ", table_name, " ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
geom ", geometry_type_name, ");")) | ||
} | ||
|
||
if (!inherits(res, 'try-error') && res == 0) { | ||
|
||
if (contents) { | ||
gpkg_add_contents(x, | ||
table_name = table_name, | ||
description = description, | ||
srs_id = srs_id, | ||
ext = ext) | ||
} | ||
|
||
res <- gpkg_add_geometry_columns( | ||
x, | ||
table_name = table_name, | ||
column_name = column_name, | ||
geometry_type_name = geometry_type_name, | ||
srs_id = srs_id, | ||
z = z, | ||
m = m | ||
) | ||
} | ||
res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#' GeoPackage Geometry Columns | ||
#' | ||
#' 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()`. | ||
#' | ||
#' @param x A _geopackage_ object, or path to GeoPackage file. | ||
#' | ||
#' @return _integer_. `1` if table created or row inserted successfully, `0` otherwise. | ||
#' @export | ||
#' @rdname gpkg-geometry-columns | ||
gpkg_create_geometry_columns <- function(x) { | ||
res <- 0 | ||
if (!"gpkg_geometry_columns" %in% gpkg_list_tables(x)) | ||
res <- gpkg_execute(x, "CREATE TABLE gpkg_geometry_columns ( | ||
table_name TEXT NOT NULL, | ||
column_name TEXT NOT NULL, | ||
geometry_type_name TEXT NOT NULL, | ||
srs_id INTEGER NOT NULL, | ||
z TINYINT NOT NULL, | ||
m TINYINT NOT NULL, | ||
CONSTRAINT pk_geom_cols PRIMARY KEY (table_name, column_name), | ||
CONSTRAINT uk_gc_table_name UNIQUE (table_name), | ||
CONSTRAINT fk_gc_tn FOREIGN KEY (table_name) REFERENCES gpkg_contents (table_name), | ||
CONSTRAINT fk_gc_srs FOREIGN KEY (srs_id) REFERENCES gpkg_spatial_ref_sys (srs_id));") | ||
res | ||
} | ||
|
||
#' @param table_name _character_. New table name. | ||
#' @param geometry_type_name _character_. Geometry type name. Default: `"GEOMETRY"` | ||
#' @param column_name _character_. Geometry column name. Default `"geom"` | ||
#' @param srs_id _integer_. Spatial Reference System ID. Must be defined in `gpkg_spatial_ref_sys` table. | ||
#' @param z _integer_. Default: `0` | ||
#' @param m _integer_. Default: `0` | ||
#' | ||
#' @export | ||
#' @rdname gpkg-geometry-columns | ||
gpkg_add_geometry_columns <- function(x, | ||
table_name, | ||
column_name, | ||
geometry_type_name = "GEOMETRY", | ||
srs_id, z, m) { | ||
res <- 0 | ||
if (!table_name %in% gpkg_collect(x, "gpkg_geometry_columns")$table_name) { | ||
values <- paste0("'", table_name, "', '", column_name, | ||
"', '", geometry_type_name, "', ", | ||
srs_id, ", ", z, ", ", m) | ||
res <- gpkg_execute(x, paste0( | ||
"INSERT INTO gpkg_geometry_columns | ||
(table_name, column_name, geometry_type_name, srs_id, z, m) | ||
VALUES (", values, ");" | ||
)) | ||
} | ||
res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.