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

ENH: allow GeoDataFrame.dissolve(by=None) #1568

Merged
merged 2 commits into from
Nov 24, 2020

Conversation

martinfleis
Copy link
Member

Resolves #1380

If no column is passed to GeoDataFrame.dissolve(), whole GeoDataFrame is considered a single group and all geometries are dissolved to a single one. It is done using a __dummy column. Since aggfunc needs to be passed to groupby, we can't create gdf directly using unary_union and agg (e.g. DataFrame.agg('first) and DataFrame.groupby.agg('first) are different methods).

@martinfleis martinfleis added this to the 0.9.0 milestone Aug 15, 2020
Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

geopandas/geodataframe.py Outdated Show resolved Hide resolved
@knaaptime
Copy link

sorry for the resolution on this pic, but one other thing that is useful in this context is the ability to dissolve by polygon contiguity, i.e. resulting in 3 features rather than one multipolygon

image

i imagine you wouldn't want to add a dependency on libpysal to support this operation, but maybe the contiguity check could be done alternatively with pygeos?

@martinfleis
Copy link
Member Author

maybe the contiguity check could be done alternatively with pygeos?

That would essentially reimplement fuzzy_contiguity from libpysal.

I think that this would be a great addition to examples gallery, maybe more than implementing it directly as a part of dissolve. If you don't care about aggfunc, you get contiguous polygons as dissolve().explode() and if you do, then there'll be that example :). Another reason is that Queen is still faster than fuzzy_contiguity (I think), so better to promote better solution.

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is ready to be merged, I think?

@martinfleis martinfleis merged commit 5856332 into geopandas:master Nov 24, 2020
@martinfleis martinfleis deleted the dissolve_none branch November 24, 2020 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Support dissolve(by=None) as unary_union of all geoms
4 participants