Search code examples
pythondataframeopenstreetmapgeojson

How to filter a geodataframe by geometry type?


I am working with Open Street Map data that I download as a dataframe through Overpass as a GEOJSON. While I am able to filter my data based on tags and subtags like so:

gdf_b = gdf_b.loc[(gdf_b['highway'] != 'service')]

I couldn't figure out the exact command to remove specific rows of a geodataframe that have a particular geometry type (like a point)

So I am looking for something like: gdf_b = gdf_b.loc[(gdf_b['geometry'].type != 'Point')]


Solution

  • You could apply and lambda

    gdf_b = gdf_b[gdf_b['geometry'].apply(lambda x : x.type!='Point' )]