regrid | R Documentation |
General function to change parameters of cells under the same geographical projection. It is implemented via raster resampling to the new grid.
regrid(x, ...)
## non-public
.regrid(grid = NULL, mul = NA, res = NA, resx = NA, resy = NA, setbound = NA,
columns = NA, rows = NA, dim = NA, bbox = NA, expand = NA,
minx = NA, miny = NA, maxx = NA, maxy = NA, cut = NA, proj4 = NA, crs = NA,
border = 0, zero = c("keep", "node", "center"), raster = FALSE, tolerance = NA,
zoom = NA, adjust = c(0.5, 0.5), verbose = FALSE, ...)
x |
Object of class |
... |
|
grid |
Reference |
mul |
|
res |
|
resx |
Positive |
resy |
Positive |
setbound |
|
columns |
Positive |
rows |
Positive |
dim |
Positive |
bbox |
|
minx |
|
miny |
|
maxx |
|
maxy |
|
cut |
|
border |
|
proj4 |
|
crs |
|
expand |
|
raster |
|
zero |
|
tolerance |
|
zoom |
|
adjust |
|
verbose |
Reporting via |
Generally, argument resample
sets a rectangular region. The area of this region is in proportion to area of output cell. Argument resample
is the value of this proportion. Each cell is interpreted as a set of adjoining rectangular figures. The value of output cells is a weighted mean of that input cells, which fall into rectangular region. The weights are defined as an partial area inside of rectangular region.
Function implements "nearest neighbor" resampling method if argument resample=0
(or, resample=FALSE
). If resample=1
(or, resample=TRUE
) and both input and output rasters have the same cell size, then resampling method is "bilinear interpolation".
Expand raster x
to 3 times with cell repeating: regrid(x,mul=3,resample=FALSE) ## nearest neighbor
;
Expand raster x
to 3 times with cell aggregation: regrid(x,mul=3,resample=TRUE) ## bilinear interpolation
;
Contract raster x
to 3 times without cell aggregation: regrid(x,mul=1/3,resample=FALSE) ## nearest neighbor
;
Contract raster x
to 3 times with cell aggregation: regrid(x,mul=1/3,resample=TRUE) ## weighted mean
;
Low-pass filtering by 3 x 3
window size: regrid(x,resample=3*3) ##
see focal_mean
However, simple contraction regrid(x,mul=1/2,resample=FALSE)
is implemented as contration with aggregation (regrid(x,mul=1/2,resample=FALSE)
), because centers or output cells are located in the nodes (crossing of boundaries of input cells).
It seems that for categorical rasters parameter resample=0
is more suitable, because nearest neigboring does not introduce new values to output raster, excepting coincidence of input cells' nodes and output cell centers.
Usage of proj4
argument specifies only desirable PROJ.4 string and does not do reprojection.
The violation of grid regualarity is due to columns and rows of image should be integer. The restoration of grid regularity is realized by spatial extension (boundary box) expansion.
regrid
returns object of class ursaRaster
.
Return value of non-public function .regrid
depends on logical value of raster
argument. If raster=FALSE
then .regrid
returns new grid without any change of sessional grid. If raster=TRUE
then .regrid
returns blank image and changes sessional grid.
Nikita Platonov platonov@sevin.ru
regrid
, focal_mean
session_grid(NULL)
print(g1 <- session_grid())
print(g2 <- regrid(g1,mul=2))
print(g3 <- regrid(g1,res=50000,lim=c(-1200000,-1400000,1600000,1800000)))
print(g4 <- regrid(g1,res=50000,lim=c(-1200100,-1400900,1600900,1800100),verbose=TRUE))
print(g5 <- regrid(g1,mul=1/4))
print(g6 <- regrid(g1,mul=1/4,cut=c(-1,-2,3,4)*25000))
print(g7 <- regrid(g1,mul=1/4,expand=1.05))
print(session_grid()) ## equal to 'g1'
print(a <- regrid(g1,mul=1/4,border=3,raster=TRUE))
print(session_grid()) ## not equal to 'g1'
session_grid(NULL)
'.makeRaster' <- function(nc=6,nr=8) {
as.ursa(t(matrix(runif(nc*nr,min=0,max=255),ncol=nc,nrow=nr)))
}
session_grid(NULL)
a <- .makeRaster(12,18)
expand <- 1/3
a1 <- regrid(regrid(a,mul=expand,resample=FALSE),a,resample=FALSE)
a2 <- regrid(regrid(a,mul=expand,resample=TRUE),a,resample=FALSE)
b <- c('source'=a,'contract'=a1,'aggregation'=a2)
print(b)
display_brick(b,grid=TRUE
,grid.lon=(seq(ncol(a)*expand+1)-1)/expand
,grid.lat=(seq(nrow(a)*expand+1)-1)/expand)
session_grid(NULL)
a <- .makeRaster(6,8)
expand <- 3
b <- c("source"=regrid(a,mul=expand,resample=FALSE,resetGrid=FALSE)
,"simple"=regrid(a,mul=expand,cascade=TRUE,resetGrid=FALSE)
,"cascaded"=regrid(a,mul=expand,cascade=FALSE,resetGrid=FALSE))
print(b)
display_brick(b)
session_grid(a)
eps <- 1e-4
r <- c(0,expand^(-2)-eps,expand^(-2)+eps,1,expand^0.5
,(expand+2/3)^2-eps,(expand+2/3)^2+eps,99)
g2 <- regrid(mul=expand)
session_grid(g2)
b <- ursa_new(bandname=sprintf("Resample=%.4f",r))
for (i in seq(b))
b[i] <- regrid(a,g2,resample=r[i])
print(b)
display_brick(b,layout=c(2,NA)
,grid=TRUE,grid.lon=seq(ncol(a)+1)-1,grid.lat=seq(nrow(a)+1)-1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.