测试变量是否为 Shapely 几何体

use*_*435 4 python shapely

我想测试变量是否是任何类型的 Shapely 几何体。该变量也可能是列表或日期时间。我可以分别测试各种 Shapely 几何形状,例如:

if type(var) in [shapely.geometry.linestring.LineString, shapely.geometry.point.Point, ...]:
   print(True)
Run Code Online (Sandbox Code Playgroud)

但是有没有类似is_shapely()函数的东西呢?

che*_*ner 8

这些类应该全部继承自BaseGeometry

if isinstance(var, shapely.geometry.base.BaseGeometry):
    print(True)
Run Code Online (Sandbox Code Playgroud)