View source: R/squareRastCells.r
squareRastCells | R Documentation |
This function resamples a raster so that cells are "square" (have the same linear dimension on each side). It uses either the "length" or "width" as a baseline distance, then resamples the other dimension to be the same. Some things to note:
Cells will not really be square on the ground because, after all, the Earth is spherical and every projection distorts shape.
If a raster is in an unprojected coordinate system (e.g., if it has WGS84 or NAD83), then the new cells (as the old cells) will have the same length/width dimensions in degrees, but cells will not actually be "square" on the ground because degrees of longitude represent smaller absolute distances at higher latitudes.
Since re-sizing cells typically means that ony a fractional cell can be fit at the edges of the extent, a template raster is created that has the same extent as the pkg raster is created. This is then extended by one cell in both directions in the dimension in which cells of the pkg raster are being expanded/contracted. The new raster is created by resampling to the extent and dimensions of this template raster. As a result, the new extent will be slightly larger than the old extent.
Owing to the preceding reason, rasters that have edges near a pole and/or the international date line may not yield workable results if the new cells extend the raster "over" the pole or date line.
squareRastCells(x, keepWidth = TRUE, ...)
x |
|
keepWidth |
Logical, if |
... |
Arguments to send to |
Raster object.
rastWithSquareCells
, resample
(raster package), resample
(terra package), aggregate
(raster package), aggregate
(terra package)
## Not run: # get WORLDCLIM elevation data elev <- raster::getData('worldclim', var='alt', res=10) # crop to Madagascar data(mad0) elev <- crop(elev, mad0) # project to equal-area: elev <- raster::projectRaster(elev, crs=getCRS('madAlbers')) # square the cells (in degrees... will not be equal-area!) byWidth <- squareRastCells(elev) byHeight <- squareRastCells(elev, keepWidth=FALSE) print('Original cell dimensions:') print(res(elev)) print('Cell dimensions, width fixed:') print(res(byWidth)) print('Cell dimensions, height fixed:') print(res(byHeight)) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.