Experimental 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)

Arguments

x

geometry input, one of:

  • an sfc geometry column (from sf)

  • a geos_geometry vector (from geos)

  • a list of raw vectors containing WKB

extent

numeric vector c(xmin, xmax, ymin, ymax) defining the raster extent. If NULL (default), derived from the bounding box of x.

dimension

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.

resolution

numeric, cell size (scalar for square cells, or c(dx, dy)). If supplied, dimension is computed from extent / resolution. Mutually exclusive with dimension.

Value

A list with class "controlledburn" containing:

runs

data.frame with columns row, col_start, col_end, id

edges

data.frame with columns row, col, weight, id

extent

the raster extent

dimension

the grid dimensions

Examples

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)
}