prep_grid {ptools} | R Documentation |
Creates vector grid cells over study area
Description
Creates grid cells of given size over particular study area.
Usage
prep_grid(outline, size, clip_level = 0, point_over = NULL, point_n = 0)
Arguments
outline |
SpatialPolygon or SpatialPolygonDataFrame that defines the area to draw grid cells over |
size |
scaler for the size of the grid cells (one side), in whatever units the outline is in |
clip_level |
, you can clip grid cells if they are not entirely inside the outlined area, defaults to |
point_over |
default |
point_n |
default 0, only used if passing in |
Details
This generates a vector grid over the study area of interest. Intentionally working with vector data for use with other feature engineering helper functions (that can pass in X/Y).
Value
A SpatialPolygonDataFrame object with columns
-
id
, integer id value (not the same as row.names!) -
x
, x centroid of grid cell -
y
, y centroid of grid cell -
cover
, proportion that grid cell is covered byoutline
-
count
, optional (only if you pass inpoint_over
)
References
Wheeler, A. P. (2018). The effect of 311 calls for service on crime in DC at microplaces. Crime & Delinquency, 64(14), 1882-1903.
Wheeler, A. P., & Steenbeek, W. (2021). Mapping the risk terrain for crime using machine learning. Journal of Quantitative Criminology, 37(2), 445-480.
Examples
library(sp) #for sp plot methods
# large grid cells
data(nyc_bor)
res <- prep_grid(nyc_bor,5000)
plot(nyc_bor)
plot(res,border='BLUE',add=TRUE)
# clipping so majority of grid is inside outline
res <- prep_grid(nyc_bor,2000,clip_level=0.5)
plot(nyc_bor)
plot(res,border='BLUE',add=TRUE)
# only grid cells that have at least one shooting
data(nyc_shoot)
res <- prep_grid(nyc_bor,2000,clip_level=0,nyc_shoot)
plot(nyc_bor)
plot(res,border='RED',add=TRUE)