prep_grid: Creates vector grid cells over study area

View source: R/sp_features.R

prep_gridR 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 0 so any cells at least touching are included

point_over

default NULL, but can pass in SpatialPoints and will only include grid cells that have at least one point

point_n

default 0, only used if passing in point_over. Will return only grid cells with greater than point_n points

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 by outline

  • count, optional (only if you pass in point_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)


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