dist_xy: Distance to nearest based on centroid

View source: R/sp_features.R

dist_xyR Documentation

Distance to nearest based on centroid

Description

Given a base X/Y dataset, calculates distance to nearest for another feature X/Y dataset

Usage

dist_xy(base, feat, bxy = c("x", "y"), fxy = c("x", "y"))

Arguments

base

base dataset (eg gridcells)

feat

feature dataset (eg another crime generator)

bxy

vector of strings that define what the base xy fields are defined as, defaults c('x','y')

fxy

vector of strings that define what the base xy fields are defined as, defaults c('x','y')

Details

This generates a distance to nearest, based on the provided x/y coordinates (so if using polygons pass the centroid). This uses kd-trees from RANN, so should be reasonably fast. But I do no projection checking, that is on you. You should not use this with spherical coordinates. Useful for feature engineering for crime generators.

Value

A vector of distances from base dataset xy to the nearest feature xy

References

Caplan, J. M., Kennedy, L. W., & Miller, J. (2011). Risk terrain modeling: Brokering criminological theory and GIS methods for crime forecasting. Justice Quarterly, 28(2), 360-381.

Wheeler, A. P., & Steenbeek, W. (2021). Mapping the risk terrain for crime using machine learning. Journal of Quantitative Criminology, 37(2), 445-480.

See Also

count_xy() for counting points inside of base polygon

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() for estimate bi-square kernel of points for features at base polygon xy coords

idw_xy() for estimate inverese distance weighted of points for features at base polygon xy coords

Examples


data(nyc_bor); data(nyc_cafe)
gr_nyc <- prep_grid(nyc_bor,15000,clip_level=0.3)
gr_nyc$dist_cafe <- dist_xy(gr_nyc,nyc_cafe)
head(gr_nyc@data)
sp::spplot(gr_nyc,zcol='dist_cafe')



ptools documentation built on Feb. 16, 2023, 10:40 p.m.