Skip to content

Instantly share code, notes, and snippets.

@brownag
Created March 6, 2023 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brownag/f11acd8b6870d0ca406aa57a1dc9fcfe to your computer and use it in GitHub Desktop.
Save brownag/f11acd8b6870d0ca406aa57a1dc9fcfe to your computer and use it in GitHub Desktop.
reprex for bug in files with multiple layers and SRS in terra (gpkg example)
library(terra)
gdal(lib = "")
data(us_states, package = "spData")
x <- vect(us_states)[1,]
y <- project(x, "EPSG:5070")
writeVector(x, "test.gpkg")
writeVector(y, "test.gpkg", layer = "test2", insert = TRUE)
# CRS is as expected
a <- vect("test.gpkg")
a
plot(a)
# CRS is wrong (matches first layer)
b <- vect("test.gpkg", layer = "test2")
b
plot(b)
# inspect gpkg contents SRS
con <- DBI::dbConnect(RSQLite::SQLite(), "test.gpkg")
DBI::dbGetQuery(con, "SELECT * FROM gpkg_contents")
DBI::dbGetQuery(con, "SELECT * FROM gpkg_spatial_ref_sys")
DBI::dbDisconnect(con)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment