I am trying to generate a set of rings around a set of points in the sf package, and have run into an issue where for some reason st_difference returns the whole first geometry despite the two inputs overlapping. I want a ring of all points between 19 and 20 units away from the center point.
Here is my sample code
library(sf)
x_coords <<- runif(n = 10, min = -100, max = 100)
y_coords <<- runif(n = 10, min = -100, max = 100)
PhenomPoints <<- SpatialPoints(coords = cbind(x_coords,y_coords))
PhenomPoints_SF <<- st_as_sf(PhenomPoints)
buffer_zones <<- st_buffer(PhenomPoints_SF, dist=20)
buffer_zones_2 <<- st_buffer(PhenomPoints_SF, dist=19)
ring <- st_difference(buffer_zones,buffer_zones_2)
plot(buffer_zones, col = "Grey")
plot(buffer_zones_2, col = "Blue", add=TRUE)
plot(ring, col = "Yellow", add=TRUE)
However, the ring seems to be basically identical to the buffer_zones. I tried using st_intersects, and it generated an intersection, but when I then used that with st_differences, it also returned the original. To see if the issue was the blank CRS, I tried it with a random CRS value and it still didn’t work.
Jonathan Rigberg is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.