Skip to contents

ogrinfo() is a wrapper of the ogrinfo command-line utility (see 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.


  layers = NULL,
  cl_arg = as.character(c("-so", "-nomd")),
  open_options = NULL,
  read_only = TRUE,
  cout = TRUE



Character string. Data source name (e.g., filename, database connection string, etc.)


Optional character vector of layer names in the source dataset.


Optional character vector of command-line arguments for the ogrinfo command-line utility in GDAL (see URL above for reference). The default is c("-so", "-nomd") (see Note).


Optional character vector of dataset open options.


Logical scalar. TRUE to open the data source read-only (the default), or FALSE to open with write access.


Logical scalar. TRUE to write info to the standard C output stream (the default). FALSE to suppress console output.


Invisibly, a character string containing information about the vector dataset, or empty string ("") in case of error.


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


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.

  # 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)

  # 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)