If I have two sf objects (polygons and multipolygons), df1 and df2, which cover the same area but at different times. I want to get the intersection of the two maps.
I currently use
<code>df_int <- st_intersection(df1, df2)
</code>
<code>df_int <- st_intersection(df1, df2)
</code>
df_int <- st_intersection(df1, df2)
which is correct but the result is pretty slow for large sf objects.
The below method is significanlty faster (10-20 times) but sometimes has different results. any idea why this might be the case?
<code>terra1 <- vect(df1)
terra2 <- vect(df2)
df_int <- intersect(terra2, terra1) %>% st_as_sf()
</code>
<code>terra1 <- vect(df1)
terra2 <- vect(df2)
df_int <- intersect(terra2, terra1) %>% st_as_sf()
</code>
terra1 <- vect(df1)
terra2 <- vect(df2)
df_int <- intersect(terra2, terra1) %>% st_as_sf()
I’ve also tried intersect(terra1, terra2)
which can be different again.
How do I get the speed benefits of terra
but have basically identical output to the sf
version?
1