minBox: Return the minimum bounding rectangle around a polygon

View source: R/minBox.R

minBoxR Documentation

Return the minimum bounding rectangle around a polygon

Description

Return the minimum bounding rectangle around a polygon

Usage

minBox(x)

Arguments

x

sf object containing only geometries of type POLYGON or MULTIPOLYGON

Value

list containing vertex points (ptx), width (width) height (height) and angle of bounding rectangle of each polygon.

Examples

dat <- sf::st_read(system.file("shape/nc.shp", package="sf"))
min_box_list <- minBox(dat)
min_box_list[[1]]

min_box_sf <- do.call(rbind, lapply(min_box_list, function(x) {
  pts_sf <- sf::st_as_sf(as.data.frame(x$pts), coords = c("X", "Y"))
  sf::st_sf(geometry = sf::st_convex_hull(sf::st_union(pts_sf)), crs = sf::st_crs(dat))
  }))
plot(sf::st_geometry(dat), col = NA, border = "blue")
plot(sf::st_geometry(min_box_sf), col = NA, border = "red", add = TRUE)


johngodlee/JLGMisc documentation built on June 29, 2024, 9:15 p.m.