3

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).

Aaron
  • 51,658
  • 28
  • 154
  • 317
user3386170
  • 1,957
  • 1
  • 28
  • 53

2 Answers2

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)

enter image description here

After -

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

enter image description here

Michael Dorman
  • 783
  • 5
  • 13
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.