简体   繁体   中英

Test if a variable is a Shapely geometry

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?

The classes should all inherit from BaseGeometry :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM