ogrinfo {gdalraster} | R Documentation |
Retrieve information about a vector data source
Description
ogrinfo()
is a wrapper of the ogrinfo
command-line
utility (see https://gdal.org/programs/ogrinfo.html).
This function lists information about an OGR-supported data source.
It is also possible to edit data with SQL statements.
Refer to the GDAL documentation at the URL above for a description of
command-line arguments that can be passed in cl_arg
.
Requires GDAL >= 3.7.
Usage
ogrinfo(
dsn,
layers = NULL,
cl_arg = as.character(c("-so", "-nomd")),
open_options = NULL,
read_only = TRUE,
cout = TRUE
)
Arguments
dsn |
Character string. Data source name (e.g., filename, database connection string, etc.) |
layers |
Optional character vector of layer names in the source dataset. |
cl_arg |
Optional character vector of command-line arguments for
the |
open_options |
Optional character vector of dataset open options. |
read_only |
Logical scalar. |
cout |
Logical scalar. |
Value
Invisibly, a character string containing information about the
vector dataset, or empty string (""
) in case of error.
Note
The command-line argument -so
provides a summary only, i.e., does not
include details about every single feature of a layer.
-nomd
suppresses metadata printing. Some datasets may contain a lot of
metadata strings.
See Also
ogr2ogr()
, the ogr_manage utilities
Examples
src <- system.file("extdata/ynp_fires_1984_2022.gpkg", package="gdalraster")
# Requires GDAL >= 3.7
if (as.integer(gdal_version()[2]) >= 3070000) {
# Get the names of the layers in a GeoPackage file.
ogrinfo(src)
# Summary of a layer
ogrinfo(src, "mtbs_perims")
# JSON format
args <- c("-json", "-nomd")
json <- ogrinfo(src, "mtbs_perims", args, cout = FALSE)
#info <- jsonlite::fromJSON(json)
# Query an attribute to restrict the output of the features in a layer
args <- c("-ro", "-nomd", "-where", "ig_year = 2020")
ogrinfo(src, "mtbs_perims", args)
# Copy to a temporary in-memory file that is writeable
src_mem <- paste0("/vsimem/", basename(src))
vsi_copy_file(src, src_mem)
print(src_mem)
# Add a column to a layer
args <- c("-sql", "ALTER TABLE mtbs_perims ADD burn_bnd_ha float")
ogrinfo(src_mem, cl_arg = args, read_only = FALSE)
# Update values of the column with SQL and specify a dialect
sql <- "UPDATE mtbs_perims SET burn_bnd_ha = (burn_bnd_ac / 2.471)"
args <- c("-dialect", "sqlite", "-sql", sql)
ogrinfo(src_mem, cl_arg = args, read_only = FALSE)
vsi_unlink(src_mem)
}