R/burn_scanline.R
burn_scanline.RdExperimental scanline sweep implementation of sparse polygon rasterization.
Produces identical output to burn_sparse() but uses a winding-number
scanline sweep instead of flood fill for interior classification.
Memory usage is O(perimeter) rather than O(bounding-box area).
burn_scanline(x, extent = NULL, dimension = NULL, resolution = NULL)geometry input, one of:
an sfc geometry column (from sf)
a geos_geometry vector (from geos)
a list of raw vectors containing WKB
numeric vector c(xmin, xmax, ymin, ymax) defining the raster
extent. If NULL (default), derived from the bounding box of x.
integer vector c(ncol, nrow) defining the grid dimensions.
If NULL (default), fitted to the extent with at most 256 cells along the
longer axis, preserving aspect ratio. Mutually exclusive with resolution.
numeric, cell size (scalar for square cells, or
c(dx, dy)). If supplied, dimension is computed from extent / resolution.
Mutually exclusive with dimension.
A list with class "controlledburn" containing:
runsdata.frame with columns row, col_start, col_end, id
edgesdata.frame with columns row, col, weight, id
extentthe raster extent
dimensionthe grid dimensions
if (requireNamespace("geos", quietly = TRUE)) {
library(geos)
poly <- as_geos_geometry("POLYGON ((0.5 0.5, 2.5 0.5, 2.5 2.5, 0.5 2.5, 0.5 0.5))")
# Defaults: extent from bbox, 256-cell fitted grid
result <- burn_scanline(poly)
# Explicit
result <- burn_scanline(poly, extent = c(0, 3, 0, 3), dimension = c(3, 3))
# By resolution
result <- burn_scanline(poly, resolution = 0.01)
}