Count simple features based on relationship with a second simple feature object
Source:R/count_features.R
count_features.Rd
Use st_join_ext()
and dplyr::count()
to count features in x based on
their spatial relationship with y. Very similar to count_sf_ext()
so they
may be merged in the future.
Usage
count_features(
x = NULL,
y = NULL,
nm = "data",
join = NULL,
.id = "name",
by = NULL,
count = NULL,
sort = FALSE,
name = NULL,
geometry = "y",
...
)
Arguments
- x
Data frame or
sf
object, Default:NULL
- y
Length 1 named
sf
list (name of y is used as count if count isNULL
) or asf
object if nm is notNULL
. y must include a column name matching the value of .id. If y isNULL
, count is required. Default:NULL
- nm
Vector of names to use with
as_sf_list()
to convert y to an sf list (if y is not already an sf list). Defaults to "data".- join
geometry predicate function; defaults to
NULL
, set tosf::st_intersects()
if y contains only POLYGON or MULTIPOLYGON objects orsf::st_nearest_feature()
if y contains other types.- .id
Column name with the values that should be added as a column to the input
sf
object.- by
A character vector of variables to join by passed to
dplyr::left_join()
.- count
Name of column to count. If
NULL
, count is set tonames(y)
(assuming y is a length 1 namedsf
list).- sort
If
TRUE
, will show the largest groups at the top.- name
The name of the new column in the output.
If omitted, it will default to
n
. If there's already a column calledn
, it will usenn
. If there's a column calledn
andnn
, it'll usennn
, and so on, addingn
s until it gets a new name.- geometry
If "y", replace x geometry with y geometry joining based on by. If by is
NULL
, by is set to the same value as count.- ...
Additional parameters passed to
st_join_ext()