rasterInfo: get detailed information about raster files

View source: R/rasterinfo.R

rasterInfoR Documentation

get detailed information about raster files

Description

This is a wrapper for the gdalinfo utility (accessed through either sf::gdal_utils or terra::describe) that returns parsed output in a nested list.

Usage

rasterInfo(x)

## S3 method for class 'rasterInfo'
print(x, all = FALSE, raw = FALSE, ...)

Arguments

x

For raster info the path to a raster file. For the print method a rasterInfo object as returned by rasterInfo.

all

if FALSE (the default) some potentially lengthy components of x are omitted. Use print(x, all=TRUE) to print everything.

raw

if TRUE Then the raw text from the gdalinfo call is printed. Use this if you think the something is being lost when the text is parsed into the list.

...

required by generic method.

Details

This is a work in progress. The information returned by gdalinfo depends on the file type described and I've developed this while working primarily with single band ArcInfo Grids and geoTIFF files so this function is unlikely to parse all available information for all file types. Use print(rasterInfo(x), raw = TRUE), x$raw if x is a rasterInfo object, to see the original text.

Some return values aren't standard for gdal but are calculated here from other values (e.g. cellsize, type, extent).

Value

A nested list of class rasterInfo with most of the information returned by gdalinfo (terra::describe()) and some additional derived elements.

path

The path to the raster file, same as x

driver

The driver used to read the file which usually matches the file's format

type

Calculated from bands will be "missing" if the raster file is missing or unreadable, "mixed" if there are multiple bands and they have varying types, otherwise the type associated with the band(s).

res

the resolution of the cells, as reported gdal (two dimensions, possible negative)

cellsize

calculated from res NA if the cells aren't square, otherwise the (positive) dimension of the cell

na.value

NA if bands have inconsistent no data values. Otherwise the no data value used by the band(s)

dim

The dimensions of the raster in cells (rows, then cols). This is from a raw line that reads "Size is" and reports cols then rows (reverse of order used here).

rows

the number of rows in the file (copied from dim)

cols

the number of columns in the file (copied from dim)

origin

the coordinates of the origin of the file (this seems to be the upper left corner). Note, gdal may report more digits than R can represent. Look at raw output to see the text as reported by gdal

approx.coords

the approximate coordinates of the corners and center. This is reported by gdalinfo but appears to be rounded, thus the "approx"

extent

A list with items xll, yll, nrow, ncol, cellsize. If cells are square these are calculated from origin, rows, cols and cellsize. This format matches the way grid extents are defined in gridio2.

nbands

The number of bands in the file.

bands

A list of lists (one per band); inner list has items

id

assigned, 1:nbands

block

the block dimensions as reported by gdal (columns, rows)

type

the storage type of the band

colorinterp

reported by gdal

stats

list of min, max, mean, sd

na.value

the No Data value used for the band. NA if there is no No Data value or if gdalinfo reports 'nan'

metadata

any band specific metadata

imagestructuremetadata

any band specific image structure metadata

metadata

any file metadata

imagestructuremetadata

any file image structure metadata

crs

The coordinate reference system in well known text format

files

a vector of all the files associated with the raster dataset

attributetable

the raster attribute table (AKA Value Attribute Table, VAT)

raw

The raw text returned by gdalinfo that was parsed to create all other items in this list

Note

The print method for rasterInfo will, by default, skip some potentially large components. Use print(x, all = TRUE) to print everything but the raw text; or print(x, raw = TRUE) to print the raw text only. If the raster file is missing, corrupt, or otherwise unreadable by gdal type will be "missing", path will be the input path, and all other items in the returned list will be NA.

References

https://gdal.org/programs/gdalinfo.html

Examples

 tif <- system.file("extdata","slope.tif" , package = "rasterPrep")
 rasterInfo(tif)


ethanplunkett/rasterPrep documentation built on Sept. 17, 2024, 1:05 p.m.