I have a dataframe with many overlapping polygons that I would like to combine into a single shape with the value that equates to the sum of the values given to each infividual polygon.
some example data:
df <- data.frame(x = c(0.5, 1.5, 4.5, 5.5),
y = c(1, 1, 1, 1),
id = c('a', 'b', 'c', 'd'),
score = c(1, 3, 2, 4))
s_df <- SpatialPointsDataFrame(df[, c('x', 'y')], df[, 3:4]) %>%
as('sf') %>%
st_buffer(dist = 1)
plot(s_df)
I can get the union of these polygons by using the st_union function in the sf package, and I think the next step would be to do a spatial join between that and the original polygons. However, I cant figure out how to do it.
st_union gives a multipolygon object as its output, but st_intersects doesn't work with that object class, and I can't seem to make a SpatialPolygonsDataframe from a multipolygon object either.
It is such a simple task I feel like there must be some basic function that I have either overlooked or missed
Any help would be greatly appreciated