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

Dissolve sf polygons based on group_by() #53

Open
fdetsch opened this issue Nov 12, 2020 · 1 comment
Open

Dissolve sf polygons based on group_by() #53

fdetsch opened this issue Nov 12, 2020 · 1 comment
Labels
feature request New feature or request

Comments

@fdetsch
Copy link

fdetsch commented Nov 12, 2020

Not sure whether this goes way beyond the scope of the poorman, but would basic dissolve functionality for sf objects - as offered by dplyr - be something you might want to think about for a future release? A quick example of what I mean can be found here.

Here's the condensed dplyr approach from above link:

library(raster)
library(sf)
library(dplyr)

## regions
regions = getData(
  country = "GBR"
  , level = 2
  , path = tmpDir()
) %>% 
  st_as_sf() %>% 
  filter(NAME_1 == "England")

plot(regions['NAME_2'])

## dissolve
england = regions %>% 
  group_by(NAME_1) %>% 
  summarise()

plot(england)

The poorman currently fails to carry out the group_by() operation with an

"Error in order(y) : unimplemented type 'list' in 'orderVector1'"

@fdetsch fdetsch added the feature request New feature or request label Nov 12, 2020
@nathaneastwood
Copy link
Owner

I've looked into this a little bit and I fixed the problems with group_by() (locally, not yet pushed). However the way that this works for {dplyr} is they provide a way for package authors to create methods for their S3 generics (see here). Therefore when you run regions %>% group_by(NAME_1), the output class is [1] "sf" "grouped_df" "tbl_df" "tbl" "data.frame". Hence when you call summarise() on this output, it dispatches to summarise.sf() which uses some of {dplyr}'s functionality so unfortunately, without buy-in from package authors, you will never really be able to use {sf} with {poorman} unless I were to implement these methods myself.

nathaneastwood added a commit that referenced this issue Nov 15, 2020
Goes towards fixing issues described in #53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants