i have a the following error message
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\IPython\core\interactiveshell.py", line 2721, in run_code
exec code_obj in self.user_global_ns, self.user_ns
File "<ipython-input-257-84ae6ec7b6f6>", line 1, in <module>
accuracy.ra_os
File "<ipython-input-255-a91d95432efe>", line 32, in ra_os
return np.average([(ref.intersection(s).area/s.area) for s in seg])
TypeError: 'Polygon' object is not iterable
where Polygon is the Polygon class
of shapely.
i have my own class Accuracy: stat values between reference (one) and segmented (one or more) polygons
ref = <shapely.geometry.polygon.Polygon at 0x4997b38>
seg = [<shapely.geometry.polygon.Polygon at 0x4b972e8>, <shapely.geometry.polygon.Polygon at 0x49c7390>]
import math
import numpy as np
from shapely.geometry import Polygon
nan = np.nan
class Accuracy(object):
def __init__(self, ref, seg=None):
self.ref = ref
self.seg = seg
@property
def area(self):
return self.ref.area
@property
def perimeter(self):
return self.ref.length
@property
def centroidX(self):
return self.ref.centroid.x
@property
def centroidY(self):
return self.ref.centroid.y
@property
def segments(self):
if self.seg:
return len(self.seg)
else:
return 0
@property
def ra_or(self):
if self.seg:
return np.average([(ref.intersection(s).area/ref.area) for s in seg])
else:
return nan
@property
def ra_os(self):
if self.seg:
return np.average([(ref.intersection(s).area/s.area) for s in seg])
else:
return nan
accuracy = Accuracy(ref, seg_overlap) accuracy.ra_os
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\IPython\core\interactiveshell.py", line 2721, in run_code
exec code_obj in self.user_global_ns, self.user_ns
File "<ipython-input-45-84ae6ec7b6f6>", line 1, in <module>
accuracy.ra_os
File "<ipython-input-7-1e04291926b0>", line 35, in ra_os
return np.average([(ref.intersection(s).area/s.area) for s in seg])
TypeError: 'Polygon' object is not iterable
if i run the function outside the class i have not this error
np.average([(ref.intersection(s).area/ref.area) for s in seg_overlap])
Out[47]: 0.48709794373000681