classRaster.Extract: Extract portion of raster images

ExtractR Documentation

Extract portion of raster images

Description

This operator is used to get single band or subset of bands from multi-band ursaRaster object. Another purpose is get portions of data including data reading from files.

Usage

## S3 method for class 'ursaRaster'
x[i, j, ..., drop = FALSE]

Arguments

x

ursaRaster object

i

Integer or character. If integer, then band index, specifying bands to extract. If character, either list of band names or character sting for regular expression to match band index. In the (spatial, temporal) interpretation of ursaRaster object j points to temporal component.

j

Integer. Line index, specifying lines to extract.

...

Mentioned for consistence with internal generic function [.
Use regexp=FALSE for matching by match, and regexp=TRUE for matching by Perl-compatible regexps case insensitive grep. Default is FALSE.

drop

Not used. For consistence with generic function.

Details

Operator ⁠\sQuote{[}⁠ is high-level implementation for data reading. If x$value item is not applicable, then value of ursaRaster is not in memory. In this case the controlled by i and j portion is read to memory. If both i and j are missing, then x[] reads all values from file.

x[,j] is appropriate for time series analysis and processing in the case bands have relation to temporal observation. Use regrid for geographical subset and cropping.

Value

ursaRaster object with extracter bands. Values ($value item) are in memory.

Warning

It is not allowed to read simultaneously portion of bands and portion of lines from file, e.g.,

   x <- open_envi(fname)
   y <- x[2:3,10:20]
   close(x)

Such brunch is not implemented in code. You use one of the followed tricks:

   x <- open_envi(fname)
   y <- x[2:3][,20:30]
   close(x)

or

   x <- open_envi(fname)
   y <- x[,20:30][2:3]
   close(x)

Author(s)

Nikita Platonov platonov@sevin.ru

Examples

session_grid(NULL)
## Prepare
session_grid(regrid(mul=1/8))
a <- pixelsize()
w <- c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"
      ,"MondayAgain")
b <- rep(a/mean(a),length(w))+seq(length(w))-1
bandname(b) <- w
nr <- ursa_rows(b)
bottom <- (as.integer(nr/2)):nr
write_envi(b,"tmp1",compress=FALSE,interleave="bil")

## Extract
print(b["Monday",regexp=TRUE])
print(b["Monday",regexp=FALSE])
print(b["s"])
print(b["^s"])
d1 <- b[6,bottom]
rm(b)

## Read from file
b <- open_envi("tmp1")
print(b[])
print(b[-c(6:8)])
d2 <- b[,bottom][6] ## don't use b[6,bottom]
close(b)
envi_remove("tmp1")

## Compare
print(d1)
print(d2)

nplatonov/ursa documentation built on May 8, 2024, 6:02 p.m.