allocate: Rasterization of point data into grid cells

allocateR Documentation

Rasterization of point data into grid cells

Description

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.

Usage

allocate(vec, coords = c("x", "y"), nodata = NA, attr = ".+", fun = c("mean", "sum", "n"),
         cellsize = NA, resetGrid = FALSE, verbose = FALSE)

Arguments

vec

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.

coords

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.

fun

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)

nodata

Numeric of length 1. This value used to mark NA values in the writing to file.

attr

Pattern in the format of regular expressions, which is used to select required columns in data frame. By default (".*") all columns are used.

cellsize

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.

resetGrid

Logical. If TRUE then existing base grid (from session_grid()) will be overwritten. Otherwise using of current grid will be attempted.

verbose

Logical. Some output in console. Primarily for debug purposes.

Details

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

Value

Object of class ursaRaster

Author(s)

Nikita Platonov platonov@sevin.ru

Examples

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)

ursa documentation built on Oct. 17, 2023, 5:11 p.m.