Skip to content

Dissolve using dask-geopandas #313

Open
@emaildipen

Description

@emaildipen

I have around 200k polygons in a shapefile, and I want to dissolve the polygons that are connected to each other. ArcGIS offers simple techniques to achieve this, but I was wondering if there are quicker ways to do it. I’ve tried the following but it took ages to execute.

import dask-geopands as dd

# Read the shapefile
ddf = dd.read_file(input_shapefile, npartitions=10)


# Dissolve polygons that are connected with each other
ddf['dissolve'] = 1  # Create a dummy column for dissolving
dissolved_gdf = ddf.dissolve('dissolve', split_out=11, sort=False)
    
# Explode the dissolved multipolygon into individual polygons and reset index
dissolved_gdf = dissolved_gdf.explode().reset_index(drop=True)
    
# Add an index column
dissolved_gdf['index'] = dissolved_gdf.index
    
dissolved_gdf.compute().to_file(output_shapefile_filled, use_arrow=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions