par_merge_grid {chopin} | R Documentation |
Merge adjacent grid polygons with given rules
Description
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 internal function par_make_grid
,
which has "CGRIDID"
as the unique id field.
Usage
par_merge_grid(
points_in = NULL,
grid_in = NULL,
grid_min_features = NULL,
merge_max = 4L
)
Arguments
points_in |
|
grid_in |
|
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 |
Value
A sf
or SpatVector
object of computation grids.
Note
This function will not work properly if grid_in
has
more than one million grids.
Author(s)
Insang Song
References
Polsby DD, Popper FJ. (1991). The Third Criterion: Compactness as a Procedural Safeguard Against Partisan Gerrymandering. Yale Law & Policy Review, 9(2), 301–353.
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
lastpar <- par(mfrow = c(1, 1))
library(sf)
library(igraph)
library(dplyr)
library(spatstat.random)
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)
plot(sf::st_geometry(dg_merged))
par(lastpar)