assign_points() gives each point, such as a building, a household or a
GPS reading, the unit that holds it, with one fixed rule for points on
the line between two units, so the answer does not depend on the row
order of either layer. Footprints cut by a unit line go to the unit
holding most of their area.
Usage
assign_points(points, x, rule = c("within", "nearest"), max_dist = Inf)Arguments
- points
An
sforsfcof points, or of polygons such as building footprints, in the CRS ofx.- x
An
sfobject (orsfc) of polygons.- rule
"within"(default) leaves points outside every unit unassigned, and"nearest"gives them the nearest unit.- max_dist
With
rule = "nearest", the largest distance, in CRS units, at which a point outside every unit still gets the nearest one. The defaultInftakes no limit.
Details
A point inside one unit gets it. A point on the line between units goes
to the unit that holds a point a hair to its northeast (a millionth of
the layer's width east and north), the convention of raster cells and
half-open intervals, and a point at a corner the hair does not settle
goes to the unit whose centroid is the furthest north and then east.
Among overlapping units with the same centroid, the smallest gets it.
Either way the rule reads geometry, not row order, except among units
of the same centroid and area, such as two copies of one footprint, or
a rectangle and the same rectangle turned a quarter turn. These go by
row order, and check_units() reports them as duplicates or overlaps.
A footprint goes to the unit holding most of its area. Among units
holding equal shares, it goes to the one holding its centroid, by the
rule for points, or else to the one the rule for a corner picks. A
unit that only touches it, along a line or at a corner, holds none of
it. A footprint that lies in no unit follows rule by its centroid.
The other functions of the package that read points, such as
measure_units() and split_units(), use the same rule.
See also
measure_units() to sum weights of points per unit.
Other input functions:
assign_units(),
build_blocks(),
delineate_settlements(),
measure_units()
Examples
cells <- sf::st_make_grid(
sf::st_bbox(c(xmin = 0, ymin = 0, xmax = 200, ymax = 100)),
cellsize = 100
)
x <- sf::st_set_crs(cells, 32630)
pts <- sf::st_sfc(
sf::st_point(c(50, 50)), sf::st_point(c(100, 50)),
sf::st_point(c(250, 50)),
crs = 32630
)
assign_points(pts, x)
#> [1] 1 2 NA
assign_points(pts, x, rule = "nearest")
#> [1] 1 2 2