Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/timkiely/st_make_hexagon_bins

Create hexagon bins as an sf MultiPolygon object to overlay an sf object
https://github.com/timkiely/st_make_hexagon_bins

Last synced: 3 months ago
JSON representation

Create hexagon bins as an sf MultiPolygon object to overlay an sf object

Awesome Lists containing this project

README

        

---
title: "st_make_hexagon_bins"
output: github_document
---

```{r}
suppressPackageStartupMessages({
library(sf)
library(sp)
})

smpl_points <- read_sf("manhattan_sample_points.geojson")
```

Function takes an sf object as input and returns a MultiPolygon sf object.

```{r}
st_make_hexagons <- function(x, n = 100){
set.seed(1)
hexs <- sf::st_as_sf(sp::HexPoints2SpatialPolygons(sp::spsample(sf::as_Spatial(sf::st_geometry(x)), "hexagonal", n = n)))
hexs
}
```

```{r}
hexs <- st_make_hexagons(smpl_points, n = 100)
plot(smpl_points)
plot(st_convex_hull(st_combine(smpl_points)), add = T)
plot(hexs$geometry, add = T)
```

```{r}
hexs <- st_make_hexagons(smpl_points, n = 200)
plot(smpl_points)
plot(st_convex_hull(st_combine(smpl_points)), add = T)
plot(hexs$geometry, add = T)
```

```{r}
hexs <- st_make_hexagons(smpl_points, n = 500)
plot(smpl_points)
plot(st_convex_hull(st_combine(smpl_points)), add = T)
plot(hexs$geometry, add = T)
```

```{r}
hexs <- st_make_hexagons(smpl_points, n = 1000)
plot(smpl_points)
plot(st_convex_hull(st_combine(smpl_points)), add = T)
plot(hexs$geometry, add = T)
```