count_xy {ptools}R Documentation

Count of points in polygon

Description

Given a base X/Y dataset, calculates number of feature points that fall inside

Usage

count_xy(base, feat, weight = 1)

Arguments

base

base dataset (eg gridcells), needs to be SpatialPolygonsDataFrame

feat

feature dataset (eg another crime generator), needs to be SpatialPointsDataFrame

weight

if 1 (default), does not use weights, else pass in string that is the variable name for weights in feat

Details

This generates a count (or weighted count) of features inside of the base areas. Both should be projected in the same units. Uses sp::over() methods in the function.

Value

A vector of counts (or weighted sums)

References

Wheeler, A. P. (2019). Quantifying the local and spatial effects of alcohol outlets on crime. Crime & Delinquency, 65(6), 845-871.

See Also

dist_xy() for calculating distance to nearest

dcount_xy() for counting points within distance of base polygon

kern_xy() for estimating gaussian density of points for features at base polygon xy coords

bisq_xy() to estimate bi-square kernel weights of points for features at base polygon xy coords

idw_xy() to estimate inverse distance weights of points for features at base polygon xy coords

Examples


data(nyc_liq); data(nyc_bor)
gr_nyc <- prep_grid(nyc_bor,10000)
gr_nyc$liq_cnt <- count_xy(gr_nyc,nyc_liq)
gr_nyc$table_cnt <- count_xy(gr_nyc,nyc_cafe,'SWC_TABLES')
head(gr_nyc@data)
sp::spplot(gr_nyc,zcol='liq_cnt')



[Package ptools version 2.0.0 Index]