data.frame
R/st_layers_as_df.R
st_layers_as_df.Rd
Return properties of layers in a datasource as data.frame
st_layers_as_df(x, ..., drop_driver = TRUE, warn = TRUE)
any input that works for st_layers
's argument
dsn
or an object of class sf_layers
arguments of the function st_layers
except
dsn
if x
is equivalent to dsn
else ignored
logical; TRUE
(default) drops information about
the driver, FALSE
adds the driver as column to the returned
data.frame
logical; TRUE
(default) warns if no layer is available,
FALSE
does not warn in such a case
if no layer is available NULL
, else a data.frame
resembling the print
ed return of st_layers
with
columns
name of the layer
for each layer a string listing its geometry type(s)
number of features (if reported; see argument
do_count
of st_layers
)
number of fields
short name of each layer's crs
name of driver, if argument drop_driver
has
been set to FALSE
library(sf)
dsn <- system.file("shape", package = "sf")
st_layers_as_df(x = dsn, drop_driver = FALSE)
#> layer_name geometry_type features fields crs_name
#> 1 storms_xyz_feature 3D Line String 71 1 <NA>
#> 2 storms_xyzm_feature Measured Line String 71 1 <NA>
#> 3 storms_xyz 3D Line String 71 0 <NA>
#> 4 nc Polygon 100 14 NAD27
#> 5 storms_xyzm Measured Line String 71 0 <NA>
#> 6 olinda1 Polygon 470 6 GRS 1980(IUGG, 1980)
#> driver
#> 1 ESRI Shapefile
#> 2 ESRI Shapefile
#> 3 ESRI Shapefile
#> 4 ESRI Shapefile
#> 5 ESRI Shapefile
#> 6 ESRI Shapefile
# properties of layers of multiple datasources in one data.frame
some_dsn <- list.files(system.file("gpkg", package = "sf"), full.names = TRUE)
multiple_dsn <- c(dsn, some_dsn)
df <-
as.list(multiple_dsn) %>%
setNames(multiple_dsn) %>%
lapply(st_layers_as_df, drop_driver = FALSE) %>%
data.table::rbindlist(use.names = FALSE, idcol = "dsn")