as.data.frame {ursa} | R Documentation |
Convert raster image to a data frame
Description
as.data.frame
reorganizes ursaRaster
object into data frame, where first two columns (x
and y
) are coordinates of cells, and the rest columns are cell values.
Usage
## S3 method for class 'ursaRaster'
as.data.frame(x, ...)
# non-public
.as.data.frame(obj, band = FALSE, id = FALSE, na.rm = TRUE, all.na = FALSE,
col.names = NULL)
Arguments
x , obj |
Object of class | ||||||||||||||||||
... |
Set of arguments, which are recognized via their names (using regular expressions) and classes. Passed to non-public
| ||||||||||||||||||
band |
Logical. If | ||||||||||||||||||
id |
Logical. If | ||||||||||||||||||
na.rm |
Logical. If | ||||||||||||||||||
all.na |
Logical. If | ||||||||||||||||||
col.names |
Character vector or |
Details
The structure of voxel is kept. The number of rows for band=TRUE
is equal to the number of rows for band=FALSE
multiplied to number of bands. To extract all numeric data with destroying of voxel, you may use followed code:subset(as.data.frame(obj,band=TRUE),!is.na(z))
.
Value
Data frame.
If band=TRUE
then
x |
Horizontal coordinate of cell's midpoint |
y |
Vertical coordinate of cell's midpoint |
z |
Value |
band |
Band as a |
id |
Optional. Unique number for |
If band=FALSE
then
x |
Horizontal coordinate of cell's midpoint |
y |
Vertical coordinate of cell's midpoint |
... |
Additional columns. Names of columns are names of bands. Values of columns are values of corresponded bands. |
If ursaRaster
is projected, then data frame has additional attribute attr(...,"proj")
with value of PROJ.4 string.
Author(s)
Nikita Platonov platonov@sevin.ru
Examples
session_grid(NULL)
session_grid(regrid(res=50000,lim=c(-1200100,-1400800,1600900,1800200)))
a0 <- ursa_dummy(nband=3,min=0,max=100)
a0[a0<30 | a0>70] <- NA
names(a0) <- c("x","y","z")
print(a0)
b0 <- as.data.frame(a0)
session_grid(NULL)
a1 <- as.ursa(b0)
print(a1-a0)
session_grid(NULL)
session_grid(regrid(res=5800000))
set.seed(352)
a2 <- as.integer(ursa_dummy(nband=2,min=0,max=100))
a2[a2>50] <- NA
print(a2)
print(b1 <- as.data.frame(a2,na.rm=FALSE))
print(b2 <- as.data.frame(a2,na.rm=TRUE))
print(b3 <- as.data.frame(a2,all.na=TRUE))
print(b4 <- as.data.frame(a2,band=TRUE,na.rm=FALSE))
print(b5 <- as.data.frame(a2,band=TRUE,all.na=FALSE))
print(b6 <- as.data.frame(a2,band=TRUE,all.na=TRUE))
print(b7 <- as.data.frame(a2,band=TRUE,all.na=TRUE,id=TRUE))