resample_from_grid: Resample a Raster object from a Grid

Description Usage Arguments Value Examples

View source: R/resample_from_grid.R

Description

This function is a wrapper around the resample function. Instead of resampling a Raster object from another Raster object as in resample, this function resamples a Raster object from a SpatialPoints* grid object. In case of a RasterBrick or a RasterStack object, it resamples only the first layer and returns it as a RasterLayer object.

Usage

1
resample_from_grid(rstr, grd)

Arguments

rstr

A Raster* object (i.e. a RasterLayer or a RasterBrick object).

grd

A SpatialPoint object with points regularly spaced.

Value

A RasterLayer object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
library(sp)
library(raster)

vn <- gadmVN::gadm(level = "country")
vn <- sf::as_Spatial(vn)
# The raster of population
r <- raster(ncol = 5, nrow = 2)
# A grid of 100 points over the country:
proj <- proj4string(vn)
grid5 <- makegrid(vn, 5)
grid5 <- SpatialPoints(grid5, CRS(proj))
# Let's resample:
resample_from_grid(r, grid5)
# Also works for RasterBrick
resample_from_grid(brick(r), grid5)

## Not run: 
library(worldpopVN)
library(sf)
# download vietnam country administrative map in the internal library and in
# the working direction
country <- sptools::gadm("vietnam", "sf", 0, intlib = TRUE, save = TRUE)
# The raster of population
ppp2010 <- worldpopVN::getpop(2010)

# A grid of 100 points over the country:
proj <- proj4string(country)
grid100 <- makegrid(country, 100)
grid100 <- SpatialPoints(grid100, CRS(proj))

# Let's resample:
ppp2010rspld <- resample_from_grid(ppp2010, grid100)

# Let's compare:
ppp2010
ppp2010rspld

plot(ppp2010rspld)
plot(grid100, add = TRUE)
plot(st_geometry(st_as_sf(vn)), add = TRUE)

## End(Not run)

choisy/sptools documentation built on Aug. 22, 2019, 12:57 p.m.