raster2matrix: Convert Raster layer to a matrix or array

View source: R/raster2matrix.r

raster2matrixR Documentation

Convert Raster layer to a matrix or array

Description

raster2matrix converts a raster layer to a matrix or array. Used by readbin and writebin.

Usage

raster2matrix(RasterLayer)

raster2array(RasterLayer)

Arguments

RasterLayer

raster layer to be converted.

Author(s)

Robert K. Bauer

Examples

library('raster')
path <- system.file("test_files", package="oceanmap")
gz.files <- Sys.glob(paste0(path,'/*.gz')) # load sample-'.gz'-files
check_gzfiles(folder=path) # return file summary-table

raster.file <- readbin(gz.files[1]) # loading gz-file as raster-layer
image(raster.file)

## Example 1: converting single raster layer to matrix
image(as.matrix(raster.file)) # unflipped conversion
m <- raster2matrix(raster.file) # converting raster-layer to matrix
image(m)

## Example 2: converting double raster layer to an array
stack.file <- stack(raster.file,raster.file)
image(as.array(stack.file)[,,1]) # unflipped conversion
a <- raster2array(stack.file) # converting raster-layer to array (works also with raster2matrix)
image(a[,,1])

oceanmap documentation built on Nov. 10, 2023, 5:08 p.m.