Convert Raster layer to a matrix or array

Share:

Description

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

Usage

1
2
3
raster2matrix(RasterLayer)

raster2array(RasterLayer)

Arguments

RasterLayer

raster layer to be converted.

Author(s)

Robert K. Bauer

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
library('raster')
owd <- getwd()
setwd(system.file("test_files", package="oceanmap"))
check_gzfiles() # return file summary-table
gz.files <- Sys.glob('*.gz') # load sample-'.gz'-files

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

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.