Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

st_union issues #275

bhaskarvk opened this issue Mar 27, 2017 · 2 comments


Copy link

@bhaskarvk bhaskarvk commented Mar 27, 2017

I'm trying to migrate my tilegramsR package from sp to sf.
One of the operations I do is combine polygons by an attribute. I was using rmapshaper::ms_dissolve for it

Here's how it works in the old sp way of things


evs <- tilegramsR::Pitch_US_Population_2016_v1
plot(evs) # Each polygon is an electoral vote

# Merge electoralvote polygons to state polygons using rmapshaper
evs_states <- rmapshaper::ms_dissolve(evs, 'state')
plot(evs_states) # Each polygon is a state

Before Combining


After rmapshaper::ms_dissolve


I converted the evs to an sf object and then tried st_union after grouping by state, but I get some extra lines (see California, Florida states).

sf_evs <- st_as_sf(evs)

sf_evs_states <- dplyr::group_by(sf_evs, state) %>%
  dplyr::summarise(geometry = st_union(geometry)) %>%



Full code is uploaded at Rpubs

@bhaskarvk bhaskarvk changed the title sf_combine issues st_union issues Mar 27, 2017

This comment has been minimized.

Copy link

@edzer edzer commented Mar 27, 2017

Nice job for setting the precision: use e.g.

st_precision(sf_evs) = 10000

(or use st_set_precision in a pipe) after defining st_evs`:


This comment has been minimized.

Copy link
Contributor Author

@bhaskarvk bhaskarvk commented Mar 27, 2017

That works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.