| polygonize | R Documentation |
Converts a .vec raster into polygon features, the inverse of rasterize().
The raster is read one tile-row strip at a time; within each strip equal-valued
cells along a row collapse to a rectangle, and (with dissolve = TRUE) the
rectangles are then merged by value through spatial_dissolve() so each
distinct value becomes a single polygon spanning the whole raster. The result
is a lazy vectra_node carrying a value column and hex-WKB geometry.
polygonize(
x,
band = 1L,
dissolve = TRUE,
na_rm = TRUE,
values = "value",
crs = NA,
flush_rows = NULL
)
x |
A |
band |
Band to vectorise (1-based). Default 1. |
dissolve |
If |
na_rm |
Drop nodata cells ( |
values |
Name of the output value column. Default |
crs |
Coordinate reference system recorded on the node. Defaults to the raster's EPSG, else unknown. |
flush_rows |
Rows buffered before a spill flush. |
Extraction is the monoid fold tier (one strip at a time); the by-value
dissolve rides the sort / partition tier of spatial_dissolve(), localising
each value to a shard before the union. Geometry assembly is delegated to
sf (an optional dependency).
A vectra_node with the value column and a hex-WKB geometry column,
materialise it with collect_sf().
rasterize() for the inverse, contours() for iso-lines,
collect_sf() to materialise as sf.
m <- matrix(c(1, 1, 2, 2, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3), 4, 4,
byrow = TRUE)
f <- tempfile(fileext = ".vec")
vec_write_raster(m, f, dtype = "f64", extent = c(0, 0, 4, 4))
polys <- polygonize(f)
collect_sf(polys)
unlink(f)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.