I have a GeoPackage (.gpkg
) database with only one layer:
ogrListLayers("data/LM_data/zipped/ay_riks.gpkg")
[1] "ay_riks"
attr(,"driver")
[1] "GPKG"
attr(,"nlayers")
[1] 1
There are too many objects and I'd like to read only a subset of them based on an attribute:
library(sf)
library(rgdal)
library(tidyverse)
dta<-st_read("data/LM_data/zipped/ay_riks.gpkg",
layer = "ay_riks",
EWKB = T,
geom_column="geom",
query= "SELECT * FROM ay_riks WHERE KOMMUNKOD='2480';")
I get an error:
Reading layer `ay_riks' from data source `/Users/chihayakenji/Documents/spatial_r/data/LM_data/zipped/ay_riks.gpkg' using driver `GPKG'
Error in st_sf(x, ..., agr = agr, sf_column_name = sf_column_name) :
no simple features geometry column present
What is the correct way of doing this?
geometry_column
instead ofgeom_column
: docs:st_read(dsn, layer, ..., query = NA, options = NULL, quiet = FALSE, geometry_column = 1L, type = 0, promote_to_multi = TRUE,
although you dont need to specify it unless your table has more than one geom column or isn't a proper geometry table...