From b2afffcd54e05bac6504fa887071c5af90c86317 Mon Sep 17 00:00:00 2001 From: Alireza Adli Date: Fri, 23 Aug 2024 16:46:33 -0400 Subject: [PATCH] Collect feature_id of the duplicates --- .../remove_nrcan_duplicates.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/varennes_single_processes/remove_nrcan_duplicates.py b/varennes_single_processes/remove_nrcan_duplicates.py index 64c08b3..95b6b0f 100644 --- a/varennes_single_processes/remove_nrcan_duplicates.py +++ b/varennes_single_processes/remove_nrcan_duplicates.py @@ -74,4 +74,29 @@ for feature in varennes_nrcan_centroids.layer.getFeatures(): varennes_nrcan_centroids_df = pd.DataFrame(data) varennes_nrcan_centroids_df['ID'] = range(len(varennes_nrcan_centroids_df)) +# Removing polygones based on a diifference (tolerance variable) +# between centroid_x of polygons and centroid_y of the polygons +tolerance = 3 +counter = 0 +centroid_x = varennes_nrcan_centroids_df['centroid_x'].tolist() +centroid_y = varennes_nrcan_centroids_df['centroid_y'].tolist() +feature_ids_all = varennes_nrcan_centroids_df['feature_id'].tolist() +feature_ids = [] + +for feature_index in range(len(centroid_x)): + for next_feature_index in range(feature_index + 1, len(centroid_x)): + a_x = centroid_x[feature_index] + b_x = centroid_x[next_feature_index] + subtract_x = a_x - b_x + a_y = centroid_y[feature_index] + b_y = centroid_y[next_feature_index] + subtract_y = a_y - b_y + if abs(subtract_x) < tolerance and abs(subtract_y) < tolerance: + feature_ids.append(feature_ids_all[next_feature_index]) + +duplicated_features = {'dups_id': feature_ids} +duplicated_features_df = pd.DataFrame(duplicated_features) + +# Removing records based on the duplicated_features_df (dataframe) +