Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

readwrite

Read from, or write to, file


Description

Methods to read from or write chunks of values to or from a file. These are low level methods for programmers. Use writeRaster if you want to save an entire SpatRaster to file in one step. It is much easier to use.

To write chunks, begin by opening a file with writeStart, then write values to it in chunks. When writing is done close the file with writeStop.

Usage

## S4 method for signature 'SpatRaster'
readStart(x)

## S4 method for signature 'SpatRaster'
readStop(x)

## S4 method for signature 'SpatRaster'
readValues(x, row=1, nrows=nrow(x), col=1, ncols=ncol(x), mat=FALSE, dataframe=FALSE)

## S4 method for signature 'SpatRaster,character'
writeStart(x, filename="", overwrite=FALSE, n=4, ...)

## S4 method for signature 'SpatRaster'
writeStop(x)

## S4 method for signature 'SpatRaster,vector'
writeValues(x, v, start, nrows)

Arguments

x

SpatRaster

filename

character. Output filename

v

vector with cell values to be written

start

integer. Row number (counting starts at 1) from where to start writing v

row

positive integer. Row number to start from, should be between 1 and nrow(x)

nrows

positive integer. How many rows?

col

positive integer. Column number to start from, should be between 1 and ncol(x)

ncols

positive integer. How many columns? Default is the number of columns left after the start column

mat

logical. If TRUE, values are returned as a matrix instead of as a vector, except when dataframe is TRUE

dataframe

logical. If TRUE, values are returned as a data.frame instead of as a vector (also if matrix is TRUE)

overwrite

logical. If TRUE, filename is overwritten

n

poistive integer indicating how many copies the data may be in memory at any point in time. This is used to determine how many blocks (large) datasets need to be read

...

additional arguments for writing files as in writeRaster

Value

readValues returns a vector, matrix, or data.frame

writeStart returns a list that can be used for processing the file in chunks.

The other methods invisibly return a logical value indicating whether they were succesful or not. Their purpose is the side-effect of opening or closing files.


terra

Spatial Data Analysis

v1.2-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Roger Bivand [ctb] (<https://orcid.org/0000-0003-2392-6140>), Karl Forner [ctb], Jeroen Ooms [ctb] (<https://orcid.org/0000-0002-4035-0289>), Edzer Pebesma [ctb] (<https://orcid.org/0000-0001-8049-7069>)
Initial release
2021-05-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.