-
-
Save Nowosad/357f5ab94b39809c93e2321a8c10c066 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| library(sf) | |
| library(dplyr) | |
| library(spData) | |
| library(DBI) | |
| library(RSQLite) | |
| # save nz to a file | |
| write_sf(nz, "my_nz.gpkg", layer = "nz") | |
| # connect to the GeoPackage | |
| conn = dbConnect(RSQLite::SQLite(), "my_nz.gpkg") | |
| # check tables | |
| dbListTables(conn) | |
| # disable triggers that work on geometries | |
| triggers = dbGetQuery(conn, "SELECT name FROM sqlite_master WHERE type = 'trigger';") | |
| for (trigger_name in triggers$name) { | |
| dbExecute(conn, paste0("DROP TRIGGER IF EXISTS ", trigger_name, ";")) | |
| } | |
| # check the table structure | |
| dbGetQuery(conn, "PRAGMA table_info(nz);") | |
| # update second row | |
| dbExecute(conn, "UPDATE nz SET Name = 'New Region Name' WHERE fid = 1;") | |
| # confirm update | |
| dbGetQuery(conn, "SELECT fid, Name FROM nz WHERE fid = 1;") | |
| # disconnect | |
| dbDisconnect(conn) | |
| # check in R | |
| nz2 = read_sf("my_nz.gpkg", layer = "nz") | |
| nz2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment