Skip to content

Commit

Permalink
Add toggle for gdal_spatialite_computed_geom_column entries for #6
Browse files Browse the repository at this point in the history
  • Loading branch information
brownag committed Dec 7, 2023
1 parent a165fef commit 82465eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
9 changes: 9 additions & 0 deletions R/gpkg-view.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#' @param viewquery _character_. Query for view contents.
#' @param geom_column _character_. Column name of view geometry. Default: `"geom"`
#' @param geometry_type_name _character_. View geometry type. Default: `"GEOMETRY"`
#' @param spatialite_computed _logical_. Register definition of `geom_column` as
#' the result of a Spatialite spatial function via
#' `"gdal_spatialite_computed_geom_column"` extension.
#' Default: `FALSE`
#' @param data_type _character_. View data type. Default `"features"`
#' @param srs_id _integer_. Spatial Reference System ID. Default: `4326` (WGS84)
#' @param z _integer_. Default: `0`
Expand All @@ -18,6 +22,7 @@ gpkg_create_spatial_view <- function(g,
viewquery,
geom_column = "geom",
geometry_type_name = "GEOMETRY",
spatialite_computed = FALSE,
data_type = "features",
srs_id = 4326,
z = 0,
Expand All @@ -29,4 +34,8 @@ gpkg_execute(g, sprintf("INSERT INTO gpkg_contents (table_name, identifier, data
gpkg_execute(g, sprintf("INSERT INTO gpkg_geometry_columns (table_name, column_name, geometry_type_name, srs_id, z, m)
VALUES ('%s', '%s', '%s', %s, %s, %s)",
viewname, geom_column, geometry_type_name, srs_id, z, m))
if (spatialite_computed)
gpkg_execute(g, sprintf("INSERT INTO gpkg_extensions (table_name, column_name, extension_name, definition, scope)
VALUES ('%s', '%s', 'gdal_spatialite_computed_geom_column', 'https://gdal.org/drivers/vector/gpkg_spatialite_computed_geom_column.html', 'read-write');",
viewname, geom_column))

Check warning on line 40 in R/gpkg-view.R

View check run for this annotation

Codecov / codecov/patch

R/gpkg-view.R#L30-L40

Added lines #L30 - L40 were not covered by tests
}
14 changes: 10 additions & 4 deletions man/gpkg_create_spatial_view.Rd

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

3 changes: 2 additions & 1 deletion misc/gpkg-view-voronoi.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ gpkg_create_spatial_view(g, "my_vor", "SELECT lux.fid AS OGC_FID,
ST_VoronojDiagram(geom) AS geom2
FROM lux WHERE ID_2 <= 3",
geom_column = "geom2",
geometry_type_name = "MULTIPOLYGON")
geometry_type_name = "MULTIPOLYGON",
spatialite_computed = TRUE)
# NB: terra::vect() sensitive to geom type
gpkg_contents(g)

Expand Down

0 comments on commit 82465eb

Please sign in to comment.