sf icon indicating copy to clipboard operation
sf copied to clipboard

st_join removing geometry from y may be undesirable

Open oliverbeagley opened this issue 5 years ago • 2 comments

Currently st_join() removes the geometry from y which for some geometries may be fine, such as the case where both geometries in x and y are POINTs. However when both geometries are polygons this may be undesirable, the join will return all columns but the geometry from y but the other columns from y may lose context without their geometry.

A work around to this would be to use something like dplyr::row_number() to add a column to y that would uniquely identify the geometry, then it would get carried over in st_join() and then you could use dplyr::inner_join() to add it back in, however this isn't particularly elegant.

Is there a better way than this? Is it worth changing st_join() to allow both geometries through?

oliverbeagley avatar Aug 13 '20 16:08 oliverbeagley

At a glance, changing this line

https://github.com/r-spatial/sf/blob/f36719c43e8ceffd16107d12f35ca38dc739c538/R/join.R#L141

so that it simplifies y to a dataframe (or tibble) would work unless I'm missing something

oliverbeagley avatar Aug 13 '20 16:08 oliverbeagley

It's not that simple, but a PR to make this an option is welcome.

edzer avatar Aug 14 '20 11:08 edzer