From 524a5be08efdf5b99b578233def8c361a521eb94 Mon Sep 17 00:00:00 2001 From: James Ball <37094972+PatBall1@users.noreply.github.com> Date: Wed, 14 Jun 2023 12:34:59 +0100 Subject: [PATCH] deal with indexing in clean_crowns (#107) Stops issue with saving crowns to file --- detectree2/models/outputs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/detectree2/models/outputs.py b/detectree2/models/outputs.py index 2795f351..0425f111 100644 --- a/detectree2/models/outputs.py +++ b/detectree2/models/outputs.py @@ -356,7 +356,7 @@ def clean_crowns(crowns: gpd.GeoDataFrame, iou_threshold=0.7, confidence=0.2): print(str(index) + " / " + str(len(crowns)) + " cleaned") # if there is not a crown interesects with the row (other than itself) if crowns.intersects(shape(row.geometry)).sum() == 1: - crowns_out = pd.concat([crowns_out, row]) # retain it + crowns_out = pd.concat([crowns_out, row.to_frame().T], ignore_index=True) # retain it else: # Find those crowns that intersect with it intersecting = crowns.loc[crowns.intersects(shape(row.geometry))] @@ -382,7 +382,7 @@ def clean_crowns(crowns: gpd.GeoDataFrame, iou_threshold=0.7, confidence=0.2): else: match = match.drop("iou", axis=1) # print(index) - crowns_out = pd.concat([crowns_out, match]) + crowns_out = pd.concat([crowns_out, match], ignore_index=True) # Convert pandas into back geopandas if it is not already if not isinstance(crowns_out, gpd.GeoDataFrame): crowns_out = gpd.GeoDataFrame(crowns_out, crs=crowns.crs)