[GIS] Snap to grid with sf in R

rsfsnapping

Is there a snap to grid function available in sf for R similar to ST_SnapToGrid(geometry geomA, float size)in PostGIS? It is mentioned as a solution to non-noded intersection problem for PostGIS and am looking for a solution in R. Using other snap options with just the polygon lead to geometry errors (even with small tolerance).

Best Answer

Rounding coordinates may be equivalent to snapping all of the shapes coordinates to a regular grid.

Before -

> pnt = st_point(c(0,0))
> pol = st_buffer(pnt, 1)
> plot(pol)

enter image description here

After -

> pol[[1]] = round(pol[[1]], 1)
> plot(pol)

enter image description here