raster2matrix: Convert Raster layer to a matrix or array

Description Usage Arguments Author(s) Examples

View source: R/raster2matrix.r

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

Example output

Loading required package: maps
Loading required package: mapdata
Loading required package: raster
Loading required package: sp
Loading required package: extrafont
Registering fonts with R
  region   sat    param  res ts                    option files filetype
1   med4 modis chlagrad  4km 1d    .R2012.0.gauss3.sobel3     1      .gz
2   med4 aviso      sla 033d 7d            .dt.upd.extrac     1      .gz
3  medw4 modis     sst2  4km 1d            .r2010.0.qual0     3      .gz
4   med4 modis     chla  4km 1s      .smoothgrad.0.01-3-5     4      .gz
5   med4 avhrr     p100  4km 1m .smoothgrad.0.04-3-5.edge     1      .gz
6   med4 avhrr     sst2  4km 1m .smoothgrad.0.04-3-5.edge     1      .gz
[1] "/usr/local/lib/R/site-library/oceanmap/test_files/med4_avhrr_p100_4km_1m_20030601_20030630.smoothgrad.0.04-3-5.edge.gz"

converting matrix to RasterLayer

oceanmap documentation built on March 23, 2020, 5:06 p.m.