I have written this class:
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
As best as I can tell I need to do the whole business of __class__.__base__.__module__
because I am trying to be inclusive of all shapely objects (shapely.geometry.polygon.Polygon
and shapely.geometry.multipolygon.MultiPolygon
, for example) and that combination of attributes was I found that seemed like it would work, since all the objects that I want to include output shapely.geometry.base
.
When I run the code, however, I get a TypeError even when putting in a valid shapely.geometry.polygon.Polygon
object. I have tried the above code with shapely.geometry.base
both as a string and a module. How can this be?
Some example objects to reproduce the error:
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)