Test if a variable is a Shapely geometry

Viewed 551

I want to test if a variable is any kind of Shapely geometry. The variable might also be a list or a datetime. I can test for all kinds of Shapely geometries separately, like:

if type(var) in [shapely.geometry.linestring.LineString, shapely.geometry.point.Point, ...]:
   print(True)

But is there something like an is_shapely() function?

1 Answers

The classes should all inherit from BaseGeometry:

if isinstance(var, shapely.geometry.base.BaseGeometry):
    print(True)
Related