Skip to contents

Opens the raster at path and returns a named list with dimensions, geotransform, coordinate reference system, and per-band scale/offset values.

Usage

gdal_info(path)

Arguments

path

Character string: path to the raster file.

Value

Named list with the following elements:

path

Character: the path as supplied.

nrows

Integer: number of rows (Y pixels).

ncols

Integer: number of columns (X pixels).

nbands

Integer: number of raster bands.

geotransform

Numeric vector of length 6 (GDAL convention): [x_origin, pixel_width, rotation_x, y_origin, rotation_y, pixel_height].

crs

Character: WKT coordinate reference system string, or an empty string if not defined.

scale

Numeric vector (one per band): GDAL scale factor (1.0 if not set).

offset

Numeric vector (one per band): GDAL offset (0.0 if not set).

Details

Data values are always returned as double (float64) in memory. If the raster bands carry GDAL scale/offset metadata (e.g. packed integers), those are reported here and applied automatically by GdalReader::read_window().

Stops with an informative error if the package was built without GDAL support.

Examples

# \donttest{
if (has_gdal()) {
  info <- gdal_info(
    system.file("extdata", "tiny.tif", package = "xbioclim")
  )
  str(info)
}
#> Warning: GDAL Error 4: /tmp/RtmpRzND6Y/file31e66a80e7f7.tif: No such file or directory
#> List of 8
#>  $ path        : chr "/home/runner/work/_temp/Library/xbioclim/extdata/tiny.tif"
#>  $ nrows       : int 3
#>  $ ncols       : int 3
#>  $ nbands      : int 1
#>  $ geotransform: num [1:6] 0 1 0 0 0 1
#>  $ crs         : chr ""
#>  $ scale       : num 1
#>  $ offset      : num 0
# }