minBox | R Documentation |
Return the minimum bounding rectangle around a polygon
minBox(x)
x |
sf object containing only geometries of type |
list containing vertex points (ptx
),
width (width
) height (height
) and angle of bounding
rectangle of each polygon.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.