Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spatial view support #12

Merged
merged 2 commits into from
Dec 7, 2023
Merged

Add spatial view support #12

merged 2 commits into from
Dec 7, 2023

Conversation

brownag
Copy link
Owner

@brownag brownag commented Nov 21, 2023

@brownag
Copy link
Owner Author

brownag commented Dec 7, 2023

For example a spatial view that calculates Voronoi diagrams for a subset features of the terra Luxemburg dataset.

library(gpkg)
library(terra)
#> terra 1.7.55

gpkg_tmp <- tempfile(fileext = ".gpkg")

if (file.exists(gpkg_tmp))
  file.remove(gpkg_tmp)

v <- vect(system.file("ex", "lux.shp", package = "terra"))

gpkg_write(list(lux = v), destfile = gpkg_tmp, append = TRUE)

g <- geopackage(gpkg_tmp, connect = TRUE)

gpkg_create_spatial_view(g, "my_vor", "SELECT lux.fid AS OGC_FID, 
                                              lux.fid AS fid,
                                              ST_VoronojDiagram(geom) AS geom2 
                                       FROM lux WHERE ID_2 <= 3", 
                         geom_column = "geom2", 
                         geometry_type_name = "MULTIPOLYGON") 
                         # NB: terra::vect() sensitive to geom type
gpkg_contents(g)
#>   table_name data_type identifier description              last_change   min_x
#> 1        lux  features        lux             2023-12-07T05:23:01.564Z 5.74414
#> 2     my_vor  features     my_vor             2023-12-07T05:23:01.973Z      NA
#>      min_y    max_x    max_y srs_id
#> 1 49.44781 6.528252 50.18162   4326
#> 2       NA       NA       NA   4326

plot(gpkg_vect(g, "my_vor"))        

@brownag brownag marked this pull request as ready for review December 7, 2023 13:14
@brownag brownag merged commit 8646ba8 into main Dec 7, 2023
8 checks passed
@brownag brownag mentioned this pull request Dec 7, 2023
@brownag brownag linked an issue Dec 7, 2023 that may be closed by this pull request
@brownag brownag deleted the gpkg-view branch February 13, 2024 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add spatial views
1 participant