I have a GeoDataFrame object from geopandas with its geometry column and polygons and multipolygons from shapely.geometry.
I want to filter the dataframe and only leaving out the multipolygons.
I tried:
gdf = gdf[gdf["geometry"] == shapely.geometry.multipolygon.MultiPolygon]
I guess it could be something along the lines of "validate" if every value in the geometry column,
is instance of this shapely.geometry.multipolygon.MultiPolygon object.
How could I filter out this GeoDataFrame?
Best Answer
Use the geom_type property:
Note your question text states "leaving out the multipolygons" but your code means "keeping only the multipolygons". If you actually want to remove the MultiPolygons, the code would be:
Example:
Output: