Runs the SLIC workflow and returns supercell centers as points.
Use iter = 0 to return the initial centers before iterations.
For polygon outputs, use sc_slic(); for raster output, use sc_slic_raster()
By default, returns the same fields as sc_slic():
outcomes = c("supercells", "coordinates", "values").
Use outcomes = "values" for value summaries only.
Usage
sc_slic_points(
x,
step = NULL,
compactness,
dist_fun = "euclidean",
avg_fun = "mean",
clean = TRUE,
minarea,
iter = 10,
k = NULL,
centers = NULL,
outcomes = c("supercells", "coordinates", "values"),
chunks = FALSE,
verbose = 0
)Arguments
- x
An object of class SpatRaster (terra) or class stars (stars).
- step
Initial center spacing (alternative is
k). Provide a plain numeric value for cell units, or useuse_meters()for map-distance steps in meters (automatically converted to cells using raster resolution).- compactness
A compactness value. Use
sc_tune_compactness()to estimate it. Useuse_adaptive()to enable adaptive compactness based on local feature-space distances.- dist_fun
A supported distance name from
sc_list_distances()or a custom function that takes two numeric vectors and returns one finite, nonnegative value. Smaller values must mean greater similarity.- avg_fun
An averaging function name or custom function used to summarize values within each supercell. Supported names: "mean" and "median". A custom function must accept a numeric vector and return a single numeric value.
- clean
Should connectivity of the supercells be enforced?
- minarea
When
clean = TRUE, connected components containingminareacells or fewer are merged into an adjacent component. Ifminareais omitted or set to0, the threshold is selected automatically as one quarter of the raster cell count divided by the number of initialized centers:floor(ncell / (4 * n_centers)).- iter
Number of iterations.
- k
The number of supercells desired (alternative to
step).- centers
Optional sf object of custom centers. Requires
step.- outcomes
Character vector controlling which fields are returned. Allowed values are "supercells", "coordinates", and "values". Default is full output (
c("supercells", "coordinates", "values")). Useoutcomes = "values"for value summaries only.- chunks
Chunking option. Use
FALSEfor no chunking,TRUEfor automatic chunking based on size, or a numeric value for a fixed chunk size (in number of cells per side).- verbose
Verbosity level.
Examples
library(supercells)
vol = terra::rast(system.file("raster/volcano.tif", package = "supercells"))
# initial centers (only after local minima placement, no iterations)
init_pts = sc_slic_points(vol, step = 12, compactness = 1, iter = 0)
terra::plot(vol)
plot(sf::st_geometry(init_pts), add = TRUE, pch = 3, col = "red")
# final supercell centers
vol_pts = sc_slic_points(vol, step = 12, compactness = 1)
terra::plot(vol)
plot(sf::st_geometry(vol_pts), add = TRUE, pch = 16, col = "red")
