dist_xy | R Documentation |
Given a base X/Y dataset, calculates distance to nearest for another feature X/Y dataset
dist_xy(base, feat, bxy = c("x", "y"), fxy = c("x", "y"))
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 |
fxy |
vector of strings that define what the base xy fields are defined as, defaults |
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.
A vector of distances from base dataset xy to the nearest feature xy
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.
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
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')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.