Using input points, the bounding box is split to the predefined numbers of columns and rows. Each grid will be buffered by the radius.
Usage
par_pad_grid(
input,
mode = c("grid", "grid_advanced", "grid_quantile"),
nx = 10L,
ny = 10L,
grid_min_features = 30L,
padding = NULL,
unit = NULL,
quantiles = NULL,
merge_max = NULL,
return_wkt = FALSE,
...
)
Arguments
- input
sf or Spat* object.
- mode
character(1). Mode of region construction. One of
"grid"
(simple grid regardless of the number of features in each grid)"grid_advanced"
(merging adjacent grids with smaller number of features thangrid_min_features
). The argumentgrid_min_features
should be specified."grid_quantile"
(x and y quantiles): an argumentquantiles
should be specified.
- nx
integer(1). The number of grids along x-axis.
- ny
integer(1). The number of grids along y-axis.
- grid_min_features
integer(1). A threshold to merging adjacent grids
- padding
numeric(1). A extrusion factor to make buffer to clip actual datasets. Depending on the length unit of the CRS of input.
- unit
character(1). The length unit for padding (optional).
units::set_units
is used for padding whensf
object is used. See link for the list of acceptable unit forms.- quantiles
numeric. Quantiles for
grid_quantile
mode.- merge_max
integer(1). Maximum number of grids to merge per merged set.
- return_wkt
logical(1). Return WKT format. When
TRUE
, the return value will be a list of two WKT strings.- ...
arguments passed to the internal function
Value
A list of two,
original
: exhaustive (filling completely) and non-overlapping grid polygons in the class of inputpadded
: a square buffer of each polygon inoriginal
. Used for computation.
See also
Other Parallelization:
par_cut_coords()
,
par_grid()
,
par_hierarchy()
,
par_make_grid()
,
par_merge_grid()
,
par_multirasters()
,
par_pad_balanced()
,
par_split_list()
Examples
# data
library(sf)
options(sf_use_s2 = FALSE)
ncpath <- system.file("shape/nc.shp", package = "sf")
nc <- read_sf(ncpath)
nc <- st_transform(nc, "EPSG:5070")
# run: nx and ny should strictly be integers
nc_comp_region <-
par_pad_grid(
nc,
mode = "grid",
nx = 4L, ny = 2L,
padding = 10000)
#> Switch sf class to terra...
#> Switch terra class to sf...
par(mfcol = c(1, 2))
plot(nc_comp_region$original$geometry)
plot(nc_comp_region$padded$geometry)
nc_comp_region_wkt <-
par_pad_grid(
nc,
mode = "grid",
nx = 4L, ny = 2L,
padding = 10000,
return_wkt = TRUE)
#> Switch sf class to terra...
#> Switch terra class to sf...
nc_comp_region_wkt$original
#> [1] "POLYGON ((1054293 1348025, 1249094 1348025, 1249094 1518630, 1054293 1518630, 1054293 1348025))"
#> [2] "POLYGON ((1249094 1348025, 1443896 1348025, 1443896 1518630, 1249094 1518630, 1249094 1348025))"
#> [3] "POLYGON ((1443896 1348025, 1638697 1348025, 1638697 1518630, 1443896 1518630, 1443896 1348025))"
#> [4] "POLYGON ((1638697 1348025, 1833499 1348025, 1833499 1518630, 1638697 1518630, 1638697 1348025))"
#> [5] "POLYGON ((1054293 1518630, 1249094 1518630, 1249094 1689236, 1054293 1689236, 1054293 1518630))"
#> [6] "POLYGON ((1249094 1518630, 1443896 1518630, 1443896 1689236, 1249094 1689236, 1249094 1518630))"
#> [7] "POLYGON ((1443896 1518630, 1638697 1518630, 1638697 1689236, 1443896 1689236, 1443896 1518630))"
#> [8] "POLYGON ((1638697 1518630, 1833499 1518630, 1833499 1689236, 1638697 1689236, 1638697 1518630))"
nc_comp_region_wkt$padded
#> [1] "POLYGON ((1044293 1338025, 1044293 1528630, 1259094 1528630, 1259094 1338025, 1044293 1338025))"
#> [2] "POLYGON ((1239094 1338025, 1239094 1528630, 1453896 1528630, 1453896 1338025, 1239094 1338025))"
#> [3] "POLYGON ((1433896 1338025, 1433896 1528630, 1648697 1528630, 1648697 1338025, 1433896 1338025))"
#> [4] "POLYGON ((1628697 1338025, 1628697 1528630, 1843499 1528630, 1843499 1338025, 1628697 1338025))"
#> [5] "POLYGON ((1044293 1508630, 1044293 1699236, 1259094 1699236, 1259094 1508630, 1044293 1508630))"
#> [6] "POLYGON ((1239094 1508630, 1239094 1699236, 1453896 1699236, 1453896 1508630, 1239094 1508630))"
#> [7] "POLYGON ((1433896 1508630, 1433896 1699236, 1648697 1699236, 1648697 1508630, 1433896 1508630))"
#> [8] "POLYGON ((1628697 1508630, 1628697 1699236, 1843499 1699236, 1843499 1508630, 1628697 1508630))"