Skip to contents

Create a grid with an id column and optionally a set number of columns and rows. This documentation is incomplete the function may change.

Usage

make_location_grid(
  location = NULL,
  dist = NULL,
  diag_ratio = NULL,
  asp = NULL,
  unit = "meter",
  crs = NULL,
  cols = NULL,
  rows = NULL,
  gutter = 0,
  desc = FALSE,
  n = NULL,
  cellsize = NULL,
  what = NULL,
  style = "rect",
  .id = "id"
)

Arguments

location

A sf, sfc, or bbox object, Default: NULL. Required.

dist

buffer distance in units. Optional.

diag_ratio

ratio of diagonal distance of area's bounding box used as buffer distance. e.g. if the diagonal distance is 3000 meters and the "diag_ratio = 0.1" a 300 meter will be used. Ignored when dist is provided.

asp

Aspect ratio of width to height as a numeric value (e.g. 0.33) or character (e.g. "1:3"). If numeric, get_asp() returns the same value without modification.

unit

Units for buffer. Supported options include "meter", "foot", "kilometer", and "mile", "nautical mile" Common abbreviations (e.g. "km" instead of "kilometer") are also supported. Distance in units is converted to units matching GDAL units for x; defaults to "meter"

crs

Coordinate reference system of bounding box to return

cols, rows

Used to set n if either are not NULL; defaults to NULL. row and id are added as columns to the grid if they are provided.

gutter

Distance in units between each column cell; gutter effectively serves as a margin as the negative buffer is applied to all cells (including those at the edges of the grid).

desc

If TRUE, reverse standard order of cell id numbering; defaults FALSE

n

If n is NULL and square is TRUE, the grid is set automatically to be 10 cells wide, Default: NULL

cellsize

target cellsize

what

"polygons", "corners", "centers"; set to centers automatically if style is "circle", "circle_offset" but a buffer is applied to return circular polygons.

style

Style of cell to return with options including "rect", "square", "hex", "flat_top_hex", "circle", "circle_offset"

.id

A name to use for the cell id column.

See also

Examples

nc <- read_sf_path(system.file("shape/nc.shp", package = "sf"))

# Make a 4 by 5 grid covering a mile buffer around a location
make_location_grid(
  location = nc[24,],
  dist = 1,
  unit = "mile",
  cols = 4,
  rows = 5
)
#> Simple feature collection with 20 features and 3 fields
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -78.56248 ymin: 35.8038 xmax: -77.99183 ymax: 36.2717
#> Geodetic CRS:  NAD27
#> First 10 features:
#>    id col row                       geometry
#> 1   1   1   1 POLYGON ((-78.56248 36.1781...
#> 2   2   2   1 POLYGON ((-78.41982 36.1781...
#> 3   3   3   1 POLYGON ((-78.27716 36.1781...
#> 4   4   4   1 POLYGON ((-78.13449 36.1781...
#> 5   5   1   2 POLYGON ((-78.56248 36.0845...
#> 6   6   2   2 POLYGON ((-78.41982 36.0845...
#> 7   7   3   2 POLYGON ((-78.27716 36.0845...
#> 8   8   4   2 POLYGON ((-78.13449 36.0845...
#> 9   9   1   3 POLYGON ((-78.56248 35.9909...
#> 10 10   2   3 POLYGON ((-78.41982 35.9909...

# Make a 2 by 2 grid across a location with a 1000 meter gutter between each cell
make_location_grid(
  location = nc[24,],
  dist = 500,
  unit = "meter",
  cols = 2,
  rows = 2,
  gutter = 1000
)
#> Simple feature collection with 4 features and 3 fields
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -78.54803 ymin: 35.81553 xmax: -78.00629 ymax: 36.26004
#> Geodetic CRS:  NAD27
#>   id col row                       geometry
#> 1  1   1   1 POLYGON ((-78.54803 36.0414...
#> 2  2   2   1 POLYGON ((-78.27267 36.0414...
#> 3  3   1   2 POLYGON ((-78.54803 35.8155...
#> 4  4   2   2 POLYGON ((-78.27267 35.8155...