brownag / gpkg

Utilities for the Open Geospatial Consortium (OGC) 'GeoPackage' Format in R
http://humus.rocks/gpkg/
Creative Commons Zero v1.0 Universal
18 stars 0 forks source link

add spatial views #6

Closed brownag closed 9 months ago

brownag commented 1 year ago

Add a convenience method for the creation of spatial views: https://gdal.org/drivers/vector/gpkg.html#spatial-views

For example:

CREATE VIEW my_view AS SELECT foo.fid AS OGC_FID, foo.geom, ... FROM foo JOIN another_table ON foo.some_id = another_table.other_id
INSERT INTO gpkg_contents (table_name, identifier, data_type, srs_id) VALUES ( 'my_view', 'my_view', 'features', 4326)
INSERT INTO gpkg_geometry_columns (table_name, column_name, geometry_type_name, srs_id, z, m) values ('my_view', 'my_geom', 'GEOMETRY', 4326, 0, 0)
brownag commented 1 year ago

Also, add support for this!

Starting with GDAL 3.7.1, it is possible to define a geometry column as the result of a Spatialite spatial function. Note however that this is an extension likely to be non-interoperable with other software that does not activate Spatialite for the SQLite3 database connection. Such geometry column should be registered into the gpkg_extensions using the gdal_spatialite_computed_geom_column extension name (cf GeoPackage Spatialite computed geometry column extension), like below:

CREATE VIEW my_view AS SELECT foo.fid AS OGC_FID, AsGBP(ST_Multi(foo.geom)) FROM foo;
INSERT INTO gpkg_contents (table_name, identifier, data_type, srs_id) VALUES ('my_view', 'my_view', 'features', 4326);
INSERT INTO gpkg_geometry_columns (table_name, column_name, geometry_type_name, srs_id, z, m) VALUES ('my_view', 'my_geom', 'MULTIPOLYGON', 4326, 0, 0);
INSERT INTO gpkg_extensions (table_name, column_name, extension_name, definition, scope) VALUES ('my_view', 'my_geom', 'gdal_spatialite_computed_geom_column', 'https://gdal.org/drivers/vector/gpkg_spatialite_computed_geom_column.html', 'read-write');
brownag commented 9 months ago

Closed by #12