crosswalk_units() returns one row per pair of an old and a new unit
that overlap, with the shares of area, and of size when points are
given, they hold in common. Census rounds are compared through it, and
a frame built on old units is carried to new ones.
Arguments
- old, new
sfobjects of polygons in the same projected CRS.- old_id, new_id
The id of each unit, as a column name or a vector, or
NULL(default) for row numbers.- points
Where the size sits, as an
sforsfcof points or footprints in the same CRS, such as buildings or households, orNULL(default) for area only. Each goes to the unitassign_points()gives it.- weight
The weight of each feature of
points, as a column name or a numeric vector, orNULL(default) for 1 each. A weight is the quantity a feature stands for, not a survey weight.
Value
A data frame with one row per overlapping pair, holding old,
new, area (of the overlap), area_old and area_new (its share of
the old unit's and of the new unit's area), and with points, size
(the weight of the points in the overlap), size_old and size_new.
A size share is NA for a unit with no point, or whose points all
weigh 0. A pair can hold size
and no area, when a footprint cut by the lines of both layers goes to
two units that do not overlap.
Details
Over the new units of an old unit, area_old sums to 1 when the new
layer covers the old unit, and area_new likewise over the old units of
a new unit. Size shares sum to 1 over the points of a unit that the
other layer covers. A point on the line between two units counts once,
in the unit assign_points() gives it. Overlaps below a millionth of
the smaller unit's area are rounding noise along shared lines and are
left out.
See also
code_units(), which keeps the codes of unchanged units
through the same correspondence.
Other frame update functions:
code_units(),
renest_units()
Examples
old <- sf::st_sf(id = c("A", "B"), geometry = sf::st_sfc(
sf::st_polygon(list(rbind(c(0, 0), c(2, 0), c(2, 2), c(0, 2), c(0, 0)))),
sf::st_polygon(list(rbind(c(2, 0), c(4, 0), c(4, 2), c(2, 2), c(2, 0)))),
crs = 32630
))
new <- sf::st_sf(id = c("X", "Y"), geometry = sf::st_sfc(
sf::st_polygon(list(rbind(c(0, 0), c(3, 0), c(3, 2), c(0, 2), c(0, 0)))),
sf::st_polygon(list(rbind(c(3, 0), c(4, 0), c(4, 2), c(3, 2), c(3, 0)))),
crs = 32630
))
crosswalk_units(old, new, "id", "id")
#> old new area area_old area_new
#> 1 A X 4 1.0 0.6666667
#> 2 B X 2 0.5 0.3333333
#> 3 B Y 2 0.5 1.0000000