Learn R Programming

ursa (version 3.10.4)

as.ursa: Create raster image from R objects or GDAL raster files.

Description

as.ursa converts R base objects matrix, array, numeric, data.frame list, sp objects SpatialGridDataFrame, SpatialPixelsDataFrame and SpatialPointsDataFrame, raster objects raster, stack and brick, and GDAL raster files (using functions from rgdal package) to ursaRaster object.

Usage

as.ursa(obj, ...)
as_ursa(obj, ...)

Value

Object of class ursaRaster

Arguments

obj

R object for coercion

...

Depending on class of obj, arguments are passed to repsective functions.

Author

Nikita Platonov platonov@sevin.ru

Details

as_ursa is a synonym to as.ursa.

This is a high-level function to create ursaRaster objects. The follwed classes of R objects are implemented:

‘Data Class’‘Appropriate method’array
ursa_newmatrixursa_new
numericursa_newdata.frame
allocateSpatialPointsDataFrame (sp)allocate
SpatialPixelsDataFrame (sp)allocateSpatialGridDataFrame (sp)
ursa_newlist of ursaRaster objectsunlist
list returned by sf::gdal_readursa_newlist (general)
Items $x and $y are required, If lengths of $x and $y are equal to dim of data, then allocate, else: 1) raster grid is defined from $x and $y, 2) ursa_new is called.ggmap (ggmap)ursa_new.
raster (raster)ursa_new.brick (raster)
ursa_new.stack (raster)ursa_new.
bitmap (magick)ursa_new.character (GDAL supported file name)

Generally, allocate is used for objects with non-regular grid, and ursa_new is used for regular grids. The raster grid is defined from object properties or from sessional grid.

Color tables are supported for GDAL file names and raster objects (raster, brick, stack).

For ENVI *.hdr Labelled Raster Files there are alternatives:

  1. Read object with GDAL (read_gdal);

  2. Read object without GDAL (read_envi).

Examples

Run this code
session_grid(NULL)
a1 <- as.ursa(volcano)
print(a1)
display(a1)

session_grid(NULL)
b <- ursa_dummy(mul=1/16,bandname=format(Sys.Date()+seq(3)-1,"%A"))
print(b)

c1 <- b[[1]] ## equal to 'c1 <- as.matrix(b[1],coords=TRUE)'
str(c1)
b1a <- as.ursa(c1)
print(c(original=b[1],imported=b1a))
print(c(projection.b1a=ursa_proj(b1a)))
session_grid(NULL)
b1b <- as.ursa(c1$z)
print(b1b)
print(c(projection.b1b=ursa_proj(b1b)))

c2 <- as.data.frame(b)
str(c2)
session_grid(NULL)
b2a <- as.ursa(c2)
print(b2a)

session_grid(NULL)
attr(c2,"crs") <- NULL
b2b <- as.ursa(c2)
print(b2b)
print(ursa_grid(b2b))

c3 <- unclass(as.matrix(b,coords=TRUE))
str(c3)
session_grid(b)
b3a <- as.ursa(c3)
print(b3a)
print(ursa_grid(b3a))
session_grid(NULL)
b3b <- as.ursa(c3)
print(b3b)
print(ursa_grid(b3b))

c4 <- as.array(b)
str(c4)
session_grid(b)
b4a <- as.ursa(c4)
print(b4a)
print(ursa_grid(b4a))
session_grid(NULL)
b4b <- as.ursa(c4)
print(b4b)
print(ursa_grid(b4b))

n <- 20
c5 <- data.frame(y=runif(n,min=1000000,max=5000000)
                ,x=runif(n,min=-3000000,max=1000000)
                ,value=runif(n,min=0,max=10))
print(head(c5))
session_grid(b)
b5a <- as.ursa(c5)
print(b5a)
 ## to avoid over-timing during tests -- begin
   display(b5a)
 ## to avoid over-timing during tests -- end
session_grid(NULL)
b5b <- as.ursa(c5)
print(b5b)
 ## to avoid over-timing during tests -- begin
   display(b5b)
 ## to avoid over-timing during tests -- end

# b6 <- as.ursa(system.file("pictures/erdas_spnad83.tif",package="rgdal"))
b6 <- as.ursa(system.file("tif/geomatrix.tif",package="sf"))
print(b6)
display(b6,pal=c("black","white"),coast=FALSE,col="orange")

 ## package 'raster' is required -- begin
if (requireNamespace("raster")) {
   r <- raster::brick(system.file("external/rlogo.gri",package="raster"))
   print(r)
   b7 <- as.ursa(r)
   ursa_proj(b7) <- ""
   print(b7)
   display_rgb(b7)
}
 ## package 'raster' is required -- end

Run the code above in your browser using DataLab