Learn R Programming

spatialEco (version 2.0-1)

hexagons: Hexagons

Description

Create hexagon polygons

Usage

hexagons(x, res = 100, ...)

Value

SpatialPolygonsDataFrame OBJECT

Arguments

x

sp SpatialDataFrame class object

res

Area of resulting hexagons

...

Additional arguments passed to spsample

Examples

Run this code
 library(sf)
 if(require(sp, quietly = TRUE)) {
   data(meuse, package = "sp")
   meuse <- st_as_sf(meuse, coords = c("x", "y"), crs = 28992, 
                     agr = "constant")

hex <- hexagons(meuse, res=300)   
  plot(st_geometry(hex))
    plot(st_geometry(meuse),pch=20,add=TRUE)

# subset hexagons to intersection with points
idx <- which(apply(st_intersects(hex, meuse, sparse=FALSE), 1, any))
hex.sub <- hex[idx,] 
  plot(st_geometry(hex.sub))
    plot(st_geometry(meuse),pch=20,add=TRUE)
}

Run the code above in your browser using DataLab