def _overlap_(test_poly, truth_polys, rtree_index):
"""Calculate overlap between one polygon and all ground truth by area"""
results = []
matched_list = list(rtree_index.intersection(test_poly.geometry.bounds))
for index in truth_polys.index:
if index in matched_list:
# get the original index just to be sure
intersection_result = test_poly.geometry.intersection(
truth_polys.loc[index].geometry)
intersection_area = intersection_result.area
else:
intersection_area = 0
results.append(
pd.DataFrame({
"prediction_id": [test_poly.prediction_id],
"truth_id": [truth_polys.loc[index].truth_id],
"area": intersection_area
}))
results = pd.concat(results)
return results
Creating a pandas frame each round seems to be expensive.
Creating a pandas frame each round seems to be expensive.