R/subdivide.R

Defines functions st_subdivide.sf st_subdivide.sfc st_subdivide.sfg st_subdivide

Documented in st_subdivide

#' Return a collection of geometries resulting by subdividing a geometry
#' 
#' @name st_subdivide
#' @param x object with geometries to be subdivided
#' @param max_vertices integer; maximum size of the subgeometries (at least 8)
#' @return object of the same class as \code{x}
#' @examples
#' library(sf)
#' demo(nc, ask = FALSE, echo = FALSE)
#' x = st_subdivide(nc, 10)
#' plot(x[1])
#' @export
st_subdivide = function(x, max_vertices) UseMethod("st_subdivide")

#' @export
st_subdivide.sfg = function(x, max_vertices = 256) {
	st_subdivide(st_geometry(x), max_vertices)[[1]]
}

#' @export
st_subdivide.sfc = function(x, max_vertices = 256) {
    st_sfc(CPL_subdivide(x, max_vertices), crs = st_crs(x))
}

#' @export
st_subdivide.sf = function(x, max_vertices = 256) {
	st_set_geometry(x, st_subdivide(st_geometry(x), max_vertices))
}

Try the lwgeom package in your browser

Any scripts or data that you put into this service are public.

lwgeom documentation built on May 29, 2024, 9:40 a.m.