allocate
takes x
and y
coordinates and values from data frame, which is describing point spatial data, and puts them into cells of raster. The certain function (either mean value, sum of values, number of points) is applied for >0 points inside of the exact cell borders.
allocate(vec, coords = c("x", "y"), nodata = NA, attr = ".+", fun = c("mean", "sum", "n"),
cellsize = NA, resetGrid = FALSE, verbose = FALSE)
data.frame
. At least x
and y
should be in colnames(vec)
. Is is allowed to use "SpatialPointsDataFrame"
from package sp. The "on the fly" reprojection is not supported.
Character of length 2. Colums names, which contain coordinates of data points. Raster bands are not produced for specified columns. For misreference of coordinate columns, the attempt to find more appropriate coordinate columns is taken.
Character keyword of function, which is applied to value of points, which are dropped into the same cell. Valid values are "mean"
(mean value), "sum"
(sum of values), "n"
(number of points)
Numeric of length 1. This value used to mark NA
values in the writing to file.
Pattern in the format of regular expressions, which is used to select required columns in data frame. By default (".*"
) all columns are used.
Numeric. Desired size of cell in the raster grid. Used only when source data are not in regular grid. Default is NA
; cell size is determined automatically to exclude case of points overlapping.
Logical. If TRUE
then existing base grid (from session_grid()
) will be overwritten. Otherwise using of current grid will be attempted.
Logical. Some output in console. Primarily for debug purposes.
Object of class ursaRaster
Here fun
differs from R-styled fun
in such functions as *apply
, aggregate
.
It was refused “rasterize” for function name to distinguish with rasterize
in the package raster
# NOT RUN {
session_grid(NULL)
g1 <- session_grid(regrid(session_grid(),mul=1/10))
n <- 1000
x <- with(g1,runif(n,min=minx,max=maxx))
y <- with(g1,runif(n,min=miny,max=maxy))
z <- with(g1,runif(n,min=0,max=10))
da <- data.frame(x=x,y=y,value=z)
res <- c(mean=allocate(da,fun="mean")
,mean_=NA
,sum=allocate(da,fun="sum")
,count=allocate(da,fun="n"))
res["mean_"]=res["sum"]/res["count"]
print(res)
# }
Run the code above in your browser using DataLab