prep_hexgrid {ptools} | R Documentation |
Creates hexagon grid cells over study area
Description
Creates hexagon grid cells of given area over particular study area.
Usage
prep_hexgrid(outline, area, clip_level = 0, point_over = NULL, point_n = 0)
Arguments
outline |
SpatialPolygon or SpatialPolygonDataFrame that defines the area to draw hexgrid cells over |
area |
scaler for the area of the grid cells 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 hex grid over the study area of interest. Hexgrids are sometimes preferred over square grid cells to prevent aliasing like artifacts in maps (runs of particular values).
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
, optional (only if clip_level > 0) proportion that grid cell is covered byoutline
-
count
, optional (only if you pass inpoint_over
), total N of points over
References
Circo, G. M., & Wheeler, A. P. (2021). Trauma Center Drive Time Distances and Fatal Outcomes among Gunshot Wound Victims. Applied Spatial Analysis and Policy, 14(2), 379-393.
Examples
library(sp) #for sp plot methods
#Base example, some barely touch
hnyc <- prep_hexgrid(nyc_bor,area=20000^2)
plot(hnyc)
plot(nyc_bor,border='red',add=TRUE)
#Example clipping hexagons that have dongle hexagons
hex_clip <- prep_hexgrid(nyc_bor,area=20000^2,clip_level=0.3)
plot(hex_clip,border='blue')
plot(nyc_bor,border='red',add=TRUE)
summary(hnyc)
#Example clipping hexagons with no overlap crimes
hnyc <- prep_hexgrid(nyc_bor,area=4000^2,point_over=nyc_shoot)
plot(hnyc)
plot(nyc_shoot,pch='.',add=TRUE)