6

I have a shapefile with one column. From that column I want to keep only the records (rows) with value 50 and delete the other rows. So far, I am doing this manually, by selecting the rows with the values I want to delete and I remove them. I was wondering if there is a way to write an expression in QGIS to do this automatically. I have see this post but it's not what I am looking for. Assuming that my attribute table's values is from 20 to 100 with step 10 and the column name is DN, I want to delete all rows except the ones that have a value of 50. Below is a screenshot of the attribute table:

attribute

2

2 Answers 2

10

While the layer is selected, open "Select by Expression (Ctrl+F3)" window. Select features using this expression:

DN != 50

Start Editing mode for the layer by clicking yellow pen icon. Click the bin icon to delete the selected features. Finish the Editing mode and save the changes.

enter image description here


Another option would be to use "Extract by Expression" tool. This tool doesn't delete the features, but extract the features which match the expression. In that case, you need to use DN = 50.

enter image description here

1
  • nice suggestions but I'll stick with the first one. I believe it is more suitable for my problem.
    – Nikos
    Commented Mar 20, 2023 at 12:40
3

Open the attribute table of the shapefile, there on the menu bar you will find these two icons- Select by expression and Invert selection.

enter image description here

Click on Select by expression and write DN = 50 and then click on select feature. Now click on invert selection, it will select the features having DN not equal to 50.

Enable editing and delete these selected features.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.