The proposed answer here: Filtering by geometry type in GeoPandas
does not answer my question because it only focuses on filtering by one geometric type at a time; I am trying to do so with a list of geometric types.
I am dealing with OpenStreetMap data using the pyrosm
package, which can filter a pbf file and load it as a geodataframe. However, some of the datasets contain multiple geometric types (e.g., MultiLineString, LineString, MultiPolygon, Polygon).
In dealing with boundaries, I'd like to keep the geodataframe to only MultiPolygon and Polygon. I've tried this:
boundaries = osm.get_boundaries() # generate the gdf
boundaries = boundaries[boundaries.geometry.type in ['MultiPolygon', 'Polygon']]
Then I output it to a geopackage.
That doesn't throw any error, but leaves the LineStrings and MultiLineStrings in the output.
How do I catch MultiPolygons and Polygons and exclude multiple others?