Remove the duplicates & Finalize
This commit is contained in:
parent
b2afffcd54
commit
ba0645f798
|
@ -81,7 +81,7 @@ counter = 0
|
||||||
centroid_x = varennes_nrcan_centroids_df['centroid_x'].tolist()
|
centroid_x = varennes_nrcan_centroids_df['centroid_x'].tolist()
|
||||||
centroid_y = varennes_nrcan_centroids_df['centroid_y'].tolist()
|
centroid_y = varennes_nrcan_centroids_df['centroid_y'].tolist()
|
||||||
feature_ids_all = varennes_nrcan_centroids_df['feature_id'].tolist()
|
feature_ids_all = varennes_nrcan_centroids_df['feature_id'].tolist()
|
||||||
feature_ids = []
|
duplicated_feature_ids = []
|
||||||
|
|
||||||
for feature_index in range(len(centroid_x)):
|
for feature_index in range(len(centroid_x)):
|
||||||
for next_feature_index in range(feature_index + 1, len(centroid_x)):
|
for next_feature_index in range(feature_index + 1, len(centroid_x)):
|
||||||
|
@ -92,11 +92,18 @@ for feature_index in range(len(centroid_x)):
|
||||||
b_y = centroid_y[next_feature_index]
|
b_y = centroid_y[next_feature_index]
|
||||||
subtract_y = a_y - b_y
|
subtract_y = a_y - b_y
|
||||||
if abs(subtract_x) < tolerance and abs(subtract_y) < tolerance:
|
if abs(subtract_x) < tolerance and abs(subtract_y) < tolerance:
|
||||||
feature_ids.append(feature_ids_all[next_feature_index])
|
duplicated_feature_ids.append(feature_ids_all[next_feature_index])
|
||||||
|
|
||||||
duplicated_features = {'dups_id': feature_ids}
|
# Removing records based on the duplicated_feature_ids list
|
||||||
duplicated_features_df = pd.DataFrame(duplicated_features)
|
varennes_nrcan_centroids.layer.startEditing()
|
||||||
|
|
||||||
# Removing records based on the duplicated_features_df (dataframe)
|
|
||||||
|
|
||||||
|
|
||||||
|
features = varennes_nrcan_centroids.layer.getFeatures()
|
||||||
|
# Iterate through features in the layer
|
||||||
|
for feature in features:
|
||||||
|
if feature['feature_id'] in duplicated_feature_ids:
|
||||||
|
# Delete the feature
|
||||||
|
varennes_nrcan_centroids.layer.deleteFeature(feature.id())
|
||||||
|
|
||||||
|
# Save changes and stop editing
|
||||||
|
varennes_nrcan_centroids.layer.commitChanges()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user