R/make_grid.R
st_make_grid.RdCreate a square or hexagonal grid covering the geometry of an sf or sfc object
st_make_grid( x, cellsize = c(diff(st_bbox(x)[c(1, 3)]), diff(st_bbox(x)[c(2, 4)]))/n, offset = st_bbox(x)[c("xmin", "ymin")], n = c(10, 10), crs = if (missing(x)) NA_crs_ else st_crs(x), what = "polygons", square = TRUE, flat_topped = FALSE )
| x | |
|---|---|
| cellsize | target cellsize |
| offset | numeric of lengt 2; lower left corner coordinates (x, y) of the grid |
| n | integer of length 1 or 2, number of grid cells in x and y direction (columns, rows) |
| crs | object of class |
| what | character; one of: |
| square | logical; if |
| flat_topped | logical; if |
Object of class sfc (simple feature geometry list column) with, depending on what and square,
square or hexagonal polygons, corner points of these polygons, or center points of these polygons.
to obtain a grid covering the bounding box of a set of geometries,
pass st_as_sfc(st_bbox(x)) for argument x
sfc = st_sfc(st_polygon(list(rbind(c(0,0), c(1,0), c(1,1), c(0,0))))) plot(st_make_grid(sfc, cellsize = .1, square = FALSE))# non-default offset: plot(st_make_grid(sfc, cellsize = .1, square = FALSE, offset = c(0, .05 / (sqrt(3)/2))))