Im trying to join two sf data-frames using inner-join or left-join. These dataframes both have geometries columns inside. I keep getting the error:
Error in check_join(x, y) :
y should be a data.frame; for spatial joins, use st_joinFALSE
Reproducible example below:
df1 <- data.frame(
var = c("a", "b", "c"),
lon1 = c(20,35,45),
lat1 = c(50,10,15)
) %>% st_as_sf(coords = c("lon1", "lat1"), dim = "XY") %>%
st_set_crs(4326)
df2 <- data.frame(
var = c("a", "b", "c"),
lon2 = c(15,25,35),
lat2 = c(5,10,15)
) %>% st_as_sf(coords = c("lon2", "lat2"), dim = "XY") %>%
st_set_crs(4326)
df <- inner_join(df1, df2, by = "var")
I wouldn`t like to drop the geometry because I think that can mess up my results afterwards, but any solution is welcome
st_joinas explained in the error message. Another possibility is to create intersections between geometries (st_intersection). It depends on want you want exactly do (probably the first option) - Gilles