# Deleting polygon constituted of many parts

I have a shapefile with multiple polygons and I would like to delete those which are constituted by multiple parts, as this one:

## 2 Answers

You could use select by expression to select polygon with multiple part then delete them.

To select the polygon you may use:

• `num_geometries ( @geometry ) > 1` this will select all polygon with more than one part (polygon part with hole in them will count as one geometry)
• `num_rings( @geometry ) > 1` This will select all polygon having more than one ring, so polygon with several part or polygon with hole in them will be selected.

If you dont have polygon with hole both expression should give the same result.

You can calculate number of .geoms and select by it:

``````import geopandas as gpd
df = gpd.read_file(r"/home/bera/Desktop/GIStest/numparts.shp")

# df.head()

#     FID                                           geometry
# 0    0  MULTIPOLYGON (((588648.183 6752827.099, 588630...
# 1    1  MULTIPOLYGON (((576030.995 6750095.128, 576117...
# 2    2  MULTIPOLYGON (((577351.164 6758181.681, 577360...
# 3    3  POLYGON ((576389.752 6750858.640, 576367.159 6...
# 4    4  POLYGON ((577279.299 6751050.228, 577277.824 6.

df["partcount"] = df.apply(lambda x: len(x.geometry.geoms) if "Multi" in x.geometry.geom_type else 1, axis=1)

# df.head()

#    FID                                           geometry  partcount
# 0    0  MULTIPOLYGON (((588648.183 6752827.099, 588630...          4
# 1    1  MULTIPOLYGON (((576030.995 6750095.128, 576117...          6
# 2    2  MULTIPOLYGON (((577351.164 6758181.681, 577360...          2
# 3    3  POLYGON ((576389.752 6750858.640, 576367.159 6...          1
# 4    4  POLYGON ((577279.299 6751050.228, 577277.824 6...          1

singleparts = df.loc[df.partcount==1]
singleparts.to_file(r"/home/bera/Desktop/GIStest/singleparts.shp")
``````