% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/spatial.R
\name{spatial_snap_grid}
\alias{spatial_snap_grid}
\title{Snap a streamed layer's coordinates to a fixed grid}
\usage{
spatial_snap_grid(
  x,
  size,
  geom = "geometry",
  crs = NA,
  out_geom = NULL,
  flush_rows = NULL
)
}
\arguments{
\item{x}{A \code{vectra_node} (from \code{\link[=tbl]{tbl()}}, \code{\link[=tbl_tiff]{tbl_tiff()}}, any verb chain, ...).
It is consumed by the stream.}

\item{size}{Grid spacing in CRS units (a positive number). Coordinates are
rounded to the nearest multiple; a larger \code{size} snaps more aggressively.}

\item{geom}{Name of the input geometry column holding hex-WKB or WKT strings.
Default \code{"geometry"}. Ignored when \code{coords} is given.}

\item{crs}{Coordinate reference system of the input geometry, in any form
\code{\link[sf:st_crs]{sf::st_crs()}} accepts (EPSG integer, WKT, proj string). Defaults to the
CRS the upstream node carries, or unknown.}

\item{out_geom}{Name of the output geometry column. Defaults to \code{geom}
(or \code{"geometry"} when \code{coords} is used).}

\item{flush_rows}{Transformed rows buffered before a spill flush. Larger
values mean fewer, bigger temporary files. Defaults to
\code{getOption("vectra.spatial_flush", 5e5)}.}
}
\value{
A \code{vectra_node} of the snapped geometry with \code{x}'s attributes, backed
by temporary \code{.vtr} spills (removed when the node is garbage-collected) and
carrying the input CRS.
}
\description{
Rounds every coordinate of a streamed layer to a regular grid of spacing
\code{size} (in CRS units) and repairs the result, one batch at a time. This is the
fixed-precision snap-rounding the overlay noder
(\code{\link[=spatial_overlay]{spatial_overlay()}}) applies internally, exposed as a standalone verb: it
merges near-coincident vertices and removes the slivers that floating-point
coordinates leave between shared boundaries, so a layer can be cleaned (or
pre-noded to a common precision) without running a full overlay. Snapping is
done in C straight off the hex-WKB column; one cleaned geometry comes back per
input feature, so attributes ride through untouched.
}
\details{
Geometry travels through the engine as hex-encoded WKB in a string column and
the CRS is carried on the returned node; use \code{\link[=collect_sf]{collect_sf()}} to materialize.
The \pkg{sf} package is an optional dependency (Suggests).
}
\examples{
\dontshow{if (requireNamespace("sf", quietly = TRUE)) withAutoprint(\{ # examplesIf}
p <- sf::st_polygon(list(rbind(c(0.04, 0.03), c(1.02, 0.01),
                               c(0.98, 1.03), c(0.01, 0.97), c(0.04, 0.03))))
f <- tempfile(fileext = ".vtr")
write_vtr(data.frame(
  id = 1L, geometry = sf::st_as_binary(sf::st_sfc(p), hex = TRUE)
), f)

# Snap the jittered corners back onto a 0.1 grid.
tbl(f) |> spatial_snap_grid(0.1) |> collect_sf()
unlink(f)
\dontshow{\}) # examplesIf}
}
\seealso{
\code{\link[=spatial_snap]{spatial_snap()}} to snap toward another layer instead of a grid,
\code{\link[=spatial_overlay]{spatial_overlay()}} whose noding uses the same snap-rounding, \code{\link[=collect_sf]{collect_sf()}}.
}
