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).
Asked
Active
Viewed 1,531 times
3
Aaron
- 51,658
- 28
- 154
- 317
user3386170
- 1,957
- 1
- 28
- 53
2 Answers
2
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)
After -
> pol[[1]] = round(pol[[1]], 1)
> plot(pol)
Michael Dorman
- 783
- 5
- 13
-
I'll try this later and mark it as accepted once I've checked that it works, but it looks promising! – user3386170 Feb 04 '19 at 14:31
2
The R equivalent of the ST_SnapToGrid in PostGIS is in the lwgeom package:
# Snap to grid of 5000 m
lwgeom::st_snap_to_grid(x, 5000)
Works well to solve the non-noded intersection problem, and is quicker than applying a buffer of the same tolerance.
avianattackarmada
- 123
- 4


st_snap. – user3386170 Feb 03 '19 at 19:07