as.Raster | R Documentation |
as.Raster
converts singe-band ursaRaster
object to raster, multi-band ursaRaster
object to brick and list of ursaRaster
objects to stack. S4 classes “raster”, “brick”, and “stack” are defined in package raster.
as.Raster(obj)
## S3 method for class 'ursaRaster'
as.Raster(obj)
## S3 method for class 'list'
as.Raster(obj)
## S3 method for class 'ursaStack'
as.Raster(obj)
## S3 method for class 'NULL'
as.Raster(obj)
obj |
Object of class |
Package raster is required for conversions.
The uppercase as.
R
aster
is important, because as.raster
is used in internal functions for coercion to object of class raster
.
Single-banded ursaRaster
object (with or without colortable) is coerced to RasterLayer
. Colortables are kept.
Multi-banded ursaRaster
object is coerced to RasterBrick
. Colortables are destroyed.
Multi-layered object (list of ursaRaster
objects) is coerced to RasterStack
. Colortables are destroyed.
Either RasterLayer
, RasterBrick
, or RasterStack
object.
If package raster is not installed then return value is NULL
Package raster is marked as "Suggested".
Nikita Platonov platonov@sevin.ru
## test is skipped: raster's loading time is close to CRAN allowable test time
session_grid(NULL)
if (requireNamespace("raster")) {
usedCRS <- ursa:::.crsForceProj4()
ursa:::.crsForceProj4(TRUE) ## required for CRS comparison
session_grid(regrid(mul=1/4))
msk <- ursa_dummy(1,min=0,max=100)>40
a1 <- ursa_dummy(1,min=200,max=500)[msk]
a2 <- colorize(a1,ramp=FALSE,interval=FALSE,lazyload=FALSE)
a3 <- as.integer(ursa_dummy(3,min=0,max=255.99))
a4 <- ursa_stack(a3[msk])
if (isLayer <- TRUE) {
print(a1)
r1 <- as.Raster(a1)
message(as.character(class(r1)))
print(r1)
print(raster::spplot(r1))
b1 <- as.ursa(r1)
print(c(exported=a1,imported=b1,failed=b1-a1))
print(c(theSameValue=identical(ursa_value(a1),ursa_value(b1))
,theSameGrid=identical(ursa_grid(a1),ursa_grid(b1))))
}
if (isLayerColortable <- TRUE) {
r2 <- as.Raster(a2)
message(as.character(class(r2)))
print(r2)
print(raster::spplot(r2))
b2 <- as.ursa(r2)
print(c(theSameValue=identical(ursa_value(a2),ursa_value(b2))
,theSameGrid=identical(ursa_grid(a2),ursa_grid(b2))))
}
if (isBrickOrRGB <- TRUE) {
r3 <- as.Raster(a3)
message(as.character(class(r3)))
print(r3)
print(raster::spplot(r3))
raster::plotRGB(r3)
b3 <- as.ursa(r3)
print(c(theSameValue=identical(ursa_value(a3),ursa_value(b3))
,theSameGrid=identical(ursa_grid(a3),ursa_grid(b3))))
}
if (isStack <- TRUE) {
r4 <- as.Raster(a4)
message(as.character(class(r4)))
print(r4)
print(raster::spplot(r4))
b4 <- as.ursa(r4)
print(c(theSameValue=identical(ursa_value(a4),ursa_value(b4))
,theSameGrid=identical(ursa_grid(a4),ursa_grid(b4))))
}
ursa:::.crsForceProj4(usedCRS)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.