make_grid: Make 'stars' grid from 'sf' layer

Description Usage Arguments Value Examples

View source: R/make_grid.R

Description

Create 'stars' raster grid from bounding box of 'sf' vector layer, possibly buffered, with specified resolution.

Usage

1
make_grid(x, res, buffer = 0)

Arguments

x

An sf, sfc or sfg object

res

Required grid resolution, in CRS units of x

buffer

Buffer size around x (default is 0, i.e., no buffer)

Value

A stars raster with the grid, with all cell values equal to 1

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Sample 'sf' layer
x = st_point(c(0,0))
y = st_point(c(1,1))
x = st_sfc(x, y)
x = st_sf(x)

# Make grid
r = make_grid(x, res = 0.1, buffer = 0.5)
r[[1]][] = rep(1:3, length.out = length(r[[1]]))

# Plot
plot(r, axes = TRUE, reset = FALSE)
plot(st_geometry(x), add = TRUE, pch = 4, cex = 3, col = "red")

starsExtra documentation built on Nov. 18, 2021, 5:08 p.m.