Merge boundary-sharing (in "Rook" contiguity) grids with
fewer target features than the threshold.
This function strongly assumes that the input
is returned from the par_make_grid
,
which has "CGRIDID"
as the unique id field.
Arguments
- points_in
sf
orSpatVector
object. Target points of computation.- grid_in
sf
orSpatVector
object. The grid generated by the internal functionpar_make_grid
.- grid_min_features
integer(1). Threshold to merge adjacent grids.
- merge_max
integer(1). Maximum number of grids to merge per merged set. Default is 4. For example, if the number of grids to merge is 20 and
merge_max
is 10, the function will split the 20 grids into two sets of 10 grids.
See also
Other Parallelization:
par_cut_coords()
,
par_grid()
,
par_grid_mirai()
,
par_hierarchy()
,
par_hierarchy_mirai()
,
par_make_grid()
,
par_multirasters()
,
par_multirasters_mirai()
,
par_pad_balanced()
,
par_pad_grid()
,
par_split_list()
Examples
library(sf)
library(igraph)
#>
#> Attaching package: ‘igraph’
#> The following objects are masked from ‘package:terra’:
#>
#> blocks, compare, union
#> The following objects are masked from ‘package:future’:
#>
#> %->%, %<-%
#> The following objects are masked from ‘package:stats’:
#>
#> decompose, spectrum
#> The following object is masked from ‘package:base’:
#>
#> union
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:igraph’:
#>
#> as_data_frame, groups, union
#> The following objects are masked from ‘package:terra’:
#>
#> intersect, union
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
library(spatstat.random)
#> Loading required package: spatstat.data
#> Loading required package: spatstat.univar
#> spatstat.univar 3.1-1
#> Loading required package: spatstat.geom
#> spatstat.geom 3.3-4
#>
#> Attaching package: ‘spatstat.geom’
#> The following objects are masked from ‘package:igraph’:
#>
#> diameter, edges, is.connected, vertices
#> The following objects are masked from ‘package:terra’:
#>
#> area, delaunay, is.empty, rescale, rotate, shift, where.max,
#> where.min
#> spatstat.random 3.3-2
options(sf_use_s2 = FALSE)
dg <- sf::st_as_sfc(st_bbox(c(xmin = 0, ymin = 0, xmax = 8e5, ymax = 6e5)))
sf::st_crs(dg) <- 5070
dgs <- sf::st_as_sf(st_make_grid(dg, n = c(20, 15)))
dgs$CGRIDID <- seq(1, nrow(dgs))
dg_sample <- sf::st_sample(dg, kappa = 5e-9, mu = 15,
scale = 15000, type = "Thomas")
sf::st_crs(dg_sample) <- sf::st_crs(dg)
dg_merged <- par_merge_grid(sf::st_as_sf(dg_sample), dgs, 100)
#> ℹ The merged polygons have too complex shapes.
#> Increase threshold or use the original grids.
plot(sf::st_geometry(dg_merged))