Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/timkiely/st_make_hexagon_bins
- Owner: timkiely
- Created: 2018-03-24T19:19:25.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-03-24T19:25:44.000Z (over 6 years ago)
- Last Synced: 2024-05-21T02:52:50.314Z (6 months ago)
- Language: R
- Size: 208 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
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)
```