4

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?

Georgy
  • 12,464
  • 7
  • 65
  • 73
user8188435
  • 191
  • 5
  • 14

1 Answers1

7

The classes should all inherit from BaseGeometry:

if isinstance(var, shapely.geometry.base.BaseGeometry):
    print(True)
chepner
  • 497,756
  • 71
  • 530
  • 681