Collect feature_id of the duplicates

This commit is contained in:
Alireza Adli 2024-08-23 16:46:33 -04:00
parent 7242159aaa
commit b2afffcd54

View File

@ -74,4 +74,29 @@ for feature in varennes_nrcan_centroids.layer.getFeatures():
varennes_nrcan_centroids_df = pd.DataFrame(data) varennes_nrcan_centroids_df = pd.DataFrame(data)
varennes_nrcan_centroids_df['ID'] = range(len(varennes_nrcan_centroids_df)) 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)