lawn - hex grid to centroid to circles

geospatial
r
Tags: #<Tag:0x00007f57f80fb278> #<Tag:0x00007f57f80fb138>

#1

A lawn user asked the other day about a workflow with lawn going from hex grid to calculate a centroid for each, then buffer each centroid to circles.

You’ll want to install the dev version as there’s a fix to lawn_circle we’ll need

devtools::install_github("ropensci/lawn")

Load the library

    library(lawn)

Define an area

bbox <- c(-118.521, 33.715, -118.145, 34.179)

Make a hex grid

hex_grid <- lawn_hex_grid(extent = bbox, cellWidth = 10, units = 'miles')

Visualize

hex_grid %>% view()

Convert each hexagon in the hex grid to a GeoJSON feature
then calculate centroid on that hexagaon

centroids <- as_feature(hex_grid) %>% purrr::map(lawn_centroid) 

Buffer each point a radius of 5 miles each

res <- centroids %>% purrr::map(lawn_circle, radius = 5)

Visualize

res %>% view


comes from https://github.com/ropensci/lawn/issues/50