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.
# S3 method for ursaRaster
[(x, i, j, ...) <- 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.
ursaRaster
object
Integer or character. If integer, then band index, specifying bands to replace. 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.
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
.
ursaRaster
object or numeric (scalar, matrix
, array
). The latter is coerced to internal matrix of $value
item of ursaRaster
object.
Nikita Platonov platonov@sevin.ru
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.
Extract
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)
try(b2["six"] <- 60+6+runif(5,min=-1,max=1)) ## Data structures mismatching
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