ursa (version 3.8.8)

Replace: Assing values to the portion of raster images

Description

This operator is used to set or replace values in portion of bands or lines in ursaRaster object in memory or data writing to file.

Usage

# S3 method for ursaRaster
[(x, i, j, ...) <- value

Arguments

x

ursaRaster object

i

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

j

Mentioned for consistence with internal generic function [<-.

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.

value

ursaRaster object or numeric (scalar, matrix, array). The latter is coerced to internal matrix of $value item of ursaRaster object.

Value

If values of ursaRaster object are in memory, then modified ursaRaster object with replaced bands or lines.

If values of ursaRaster object are not applicable, then ursaRaster object as is.

Details

Operator \sQuote{[<-} is high-level implementation for data writing. 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 written to file. If both i and j are missing, then x[] <- value writes values to file wholly.

It is not implemented the simultaneously writing to file portion of bands and portion of lines.

Files (currently, ENVI Binary) are opened for reading and writing.

See Also

Extract

Examples

Run this code
# NOT RUN {
session_grid(NULL)
## Prepare
session_grid(regrid(mul=1/4))
a <- pixelsize()
w <- c("first","second","third","fourth","fifth","sixth")
b1 <- rep(a/mean(a),length(w))+seq(length(w))-1
bandname(b1) <- w
nr <- ursa_rows(b1)
bottom <- (as.integer(nr/2)):nr
write_envi(b1,"tmp1",compress=FALSE,interleave="bil")
b2 <- b1
print(b1)

## Replace
b2[1] <- 10+b1["second"]
b2[2] <- 20
try({
   data(volcano)
   b2[3] <- 30+volcano
}) ## error: unable to coerce
b2["fourth"] <- 40+as.matrix(b1[3])
b2[5] <- 50+as.array(b1[4])
set.seed(352)
b2["six"] <- 60+6+runif(5,min=-1,max=1) ## only first value is used (66.42849)
print(b2)
print(object.size(b2))

## Write
b3 <- create_envi(b2,"tmp2")
print(object.size(b3))
for (i in chunk_line(b3,0.04))
{
   b3[,i] <- b2[,i]+100
   if (5 %in% i)
      print(object.size(b3))
}
close(b3)
print(object.size(b3))
b4 <- read_envi("tmp2")
print(b4)
envi_remove("tmp[12]")
# }

Run the code above in your browser using DataLab