assign_units() gives each unit of a layer, such as a block, to one
point of a second layer, such as a settlement of a census directory, so
that every point gets a territory made of whole units. It is the
counterpart of assign_points(), which gives each point the unit that
holds it. A territory lies within one part of within, so territories
nest in the admin units the units nest in, and their lines follow the
edges of the units, that is the roads, streams and patch lines of
build_blocks().
Arguments
- x
An
sfobject of polygons in a projected CRS, such as blocks.- points
An
sfobject of points in the CRS ofx, such as the settlements of a census directory, one row per settlement.- within
The part each unit and each point lies in, such as the admin unit, as the name of a column of both
xandpoints, orNULL(default) for one part. A unit only goes to a point of its own part, so every part needs at least one point.- cut
Whether a unit holding the points of several settlements is cut between them.
TRUE(default) cuts it into the Voronoi cells of its points, so each point keeps the land nearest to it.FALSEgives it to the point nearest its center, and the other points get units only by the nearest rule, with a warning that names them.
Value
An sf object with one row per unit, the units cut between
points replaced by their pieces, in the order of x. Each row holds
the columns of x, then unit (the row of x it comes from),
point (the row of points it goes to) and seed (TRUE for the
unit holding its point), then the columns of points not already in
x, so each unit carries the codes and names of its settlement. A
column of x with the name of a computed column is replaced, and
within naming one is an error.
Details
The rule has four steps.
Each point gets the unit
assign_points()gives it among the units of its part, or the nearest unit of its part when it lies in none, as a point in a lake or just across an admin line. That unit is its seed and always goes to it.A unit that is the seed of several points is cut between them, with
cut = TRUE. Each piece keeps the columns of the unit.Every other unit goes to the nearest point of its part, measured from a point on the unit's surface, which lies inside the unit even when it is concave. Ties go to the point first in the order of coordinates, so the result does not depend on the row order of either layer. This is the Euclidean allocation of the WorldPop preEA tool, applied to whole units rather than to the plane.
A territory left in several parts of the graph of the units keeps the part holding its seed. Each other part joins the territory it shares the longest boundary with, among those holding their seed, until none is left or a part has no such neighbor, as an island, which stays with its nearest point and is named in a warning.
On the blocks of The Gambia, the wards made of the territories of the census settlements put 94.7% and 96.2% of buildings in the same ward as two published ward layers, for the 97 wards whose names match. A power diagram calibrated so that each settlement holds as many buildings as its households call for agreed less (93.9% and 95.1%), since the ratio of buildings to households varies from one ward to the next, so it is not offered.
The function gives territories, not sizes. A settlement's households
are spread over its units in proportion to their buildings with
measure_units() and ave(), as in vignette("recipes").
References
Qader, S. H., Kuepie, K., and Tatem, A. J. (2024). Automatic national census pre-Enumeration Areas for Zimbabwe in 2021, version 1.0. WorldPop, University of Southampton. doi:10.5258/SOTON/WP00797
See also
assign_points() for the unit of each point, build_blocks()
for the units, measure_units() for their sizes.
Other input functions:
assign_points(),
build_blocks(),
delineate_settlements(),
measure_units()
Examples
cells <- sf::st_make_grid(
sf::st_bbox(c(xmin = 0, ymin = 0, xmax = 600, ymax = 400)),
cellsize = 100
)
blocks <- sf::st_sf(
commune = rep(c("west", "east"), each = 12),
geometry = sf::st_set_crs(cells, 32630)[order(
sf::st_coordinates(sf::st_centroid(cells))[, 1]
)]
)
villages <- sf::st_sf(
name = c("Tanga", "Bolo", "Sira", "Kona"),
commune = c("west", "west", "east", "east"),
households = c(120, 45, 80, 60),
geometry = sf::st_sfc(
sf::st_point(c(50, 50)), sf::st_point(c(150, 350)),
sf::st_point(c(420, 130)), sf::st_point(c(470, 180)),
crs = 32630
)
)
t <- assign_units(blocks, villages, within = "commune")
table(t$name)
#>
#> Bolo Kona Sira Tanga
#> 6 7 6 6
# Sira and Kona share a block, which is cut between them
t[t$unit == t$unit[t$seed & t$name == "Sira"], c("unit", "name")]
#> Simple feature collection with 2 features and 2 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: 400 ymin: 100 xmax: 500 ymax: 200
#> Projected CRS: WGS 84 / UTM zone 30N
#> unit name geometry
#> 18 18 Sira MULTIPOLYGON (((500 100, 40...
#> 19 18 Kona MULTIPOLYGON (((400 200, 50...