From 82465ebc12a2607a66abc5af4f56066e9b7e678c Mon Sep 17 00:00:00 2001 From: "Andrew G. Brown" Date: Wed, 6 Dec 2023 21:35:19 -0800 Subject: [PATCH] Add toggle for gdal_spatialite_computed_geom_column entries for #6 --- R/gpkg-view.R | 9 +++++++++ man/gpkg_create_spatial_view.Rd | 14 ++++++++++---- misc/gpkg-view-voronoi.R | 3 ++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/R/gpkg-view.R b/R/gpkg-view.R index 1c2f89a..4b46ed8 100644 --- a/R/gpkg-view.R +++ b/R/gpkg-view.R @@ -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` @@ -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, @@ -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)) } \ No newline at end of file diff --git a/man/gpkg_create_spatial_view.Rd b/man/gpkg_create_spatial_view.Rd index 91d3089..688c60c 100644 --- a/man/gpkg_create_spatial_view.Rd +++ b/man/gpkg_create_spatial_view.Rd @@ -10,6 +10,7 @@ gpkg_create_spatial_view( viewquery, geom_column = "geom", geometry_type_name = "GEOMETRY", + spatialite_computed = FALSE, data_type = "features", srs_id = 4326, z = 0, @@ -27,16 +28,21 @@ gpkg_create_spatial_view( \item{geometry_type_name}{\emph{character}. View geometry type. Default: \code{"GEOMETRY"}} +\item{spatialite_computed}{\emph{logical}. Register definition of \code{geom_column} as +the result of a Spatialite spatial function via +\code{"gdal_spatialite_computed_geom_column"} extension. +Default: \code{FALSE}} + \item{data_type}{\emph{character}. View data type. Default \code{"features"}} -\item{srs_id}{integer. Spatial Reference System ID. Default: \code{4326} (WGS84)} +\item{srs_id}{\emph{integer}. Spatial Reference System ID. Default: \code{4326} (WGS84)} -\item{z}{integer. Default: \code{0}} +\item{z}{\emph{integer}. Default: \code{0}} -\item{m}{integer. Default: \code{0}} +\item{m}{\emph{integer}. Default: \code{0}} } \value{ -\code{1} if a new record in \code{gpkg_geometry_columns} is successfully made. +\emph{integer}. Returns \code{1} if a new record in \code{gpkg_geometry_columns} is successfully made. } \description{ Create a Spatial View diff --git a/misc/gpkg-view-voronoi.R b/misc/gpkg-view-voronoi.R index e15f850..04610da 100644 --- a/misc/gpkg-view-voronoi.R +++ b/misc/gpkg-view-voronoi.R @@ -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)