我写过这堂课:
class DSMCalc(object):
def __init__(self, footprint):
if footprint.__class__.__base__.__module__ is not 'shapely.geometry.base':
raise TypeError('footprint input geometry is not a shapely geometry based object')
self.footprint = footprint
Run Code Online (Sandbox Code Playgroud)
作为最好的,我可以告诉我需要做的全业务__class__.__base__.__module__,因为我想是包括所有匀称的对象(shapely.geometry.polygon.Polygon和shapely.geometry.multipolygon.MultiPolygon,例如)和属性组合是我发现,好像这是可行的,因为所有的对象我想包括输出shapely.geometry.base.
但是,当我运行代码时,即使放入有效shapely.geometry.polygon.Polygon对象,我也会收到TypeError .我已经尝试了上面的代码shapely.geometry.base作为字符串和模块.怎么会这样?
一些示例对象重现错误:
valid_geojson_polygon_feature = {
'properties': {"name":"test"},
'type': 'Feature',
'geometry': {
'coordinates': [[(-122.4103173469268, 37.78337247419125), (-122.41042064203376, 37.7833590750075),
(-122.41046641056752, 37.78360478527359), (-122.41047393562782, 37.783644775039576),
(-122.4103759761863, 37.78365638609612), (-122.4103173469268, 37.78337247419125)]],
'type': 'Polygon'}}
from shapely.geometry import shape as get_shape
valid_shapely_polygon_feature = get_shape(valid_geojson_polygon_feature['geometry'])
print(valid_shapely_polygon_feature.__class__.__base__.__module__)
DSMCalc(valid_shapely_polygon_feature)
Run Code Online (Sandbox Code Playgroud)