2

There is this point shapefile in QGIS (2.12). There is one column with the street name and one with the housenumber.

Is it possible to select all features that have the same street name and housenumber (not one by one, but automatically all that are alike)? If yes, what tool do I have to use or what is the expression if I "select by expression"?

  • Do I understand that right and you have a several features like lines for the streets and points the house and you want to select them all by the same time? – wittich Nov 12 '15 at 10:30
  • There is only one point shapefile from which I want to select/detect. – Grete Samsa Nov 13 '15 at 8:17
2

you can use a custom function in the 'Select by Expression' Editor. This loads your active layer from the QgsInterface and makes a list combined out of your 2 columns. Then it checks for every value pair, wheter it is more then one time in the list. I yes it Returns 'true' and selects the Feature. If the value pair is only once in the list, then the Feature ist not selected.

The function Looks like this:

from qgis.core import *
from qgis.gui import *
from qgis.utils import iface

@qgsfunction(args=-1, group='Custom')
def findDuplicates(value1, feature, parent):
layer = iface.activeLayer()
combinedList =[]
for streetnumber in layer.getFeatures():        
    combinedList.append(str(streetnumber.attribute('COLUMN_NAME_OF_STREETS')) + str(streetnumber.attribute('COLUMN_NAME_OF_HOUSE_NUMBERS')))
if combinedList.count(value1[0]+str(value1[1]))>1:
    return True
else:
    return False

You save this function and call it like this:

calling the function

Then all Features which are dublicates by housenumber and street are selected.

selection afterwards

I hope this is the solution for your Problem. Unfortunately I have no idea for an Expression.

  • Nice answer, but unfortunately it's not going to scale very well for large layers. This function has to loop through every feature in the layer for every expression evaluation. – ndawson Nov 12 '15 at 21:06
  • Thank you, Olle Onkel. That really helped for my tiny layer. :) – Grete Samsa Nov 13 '15 at 8:22
  • @Olle Onkel: I can't see feature and parent parameters in your findDuplicates() function... Anything I missed? – wiltomap Nov 16 '15 at 7:37
  • They are not used within the function. They can be neglected. Instead of using value1, also the feature could be used to get the attributes. Thats up on you. – Olle Onkel Nov 16 '15 at 8:24
2

Group Stats Plugin lets you do grouping based on columns and find aggregates such as COUNT, SUM, AVG etc. There is also option to show selected features on the map but I could not figure out whether we can filter the result e.g. count > 1

enter image description here

Edit: Including Select by Expression again

Option 1: Direct menu

Click on Select by Expression menu

enter image description here

Option 2: Through attributes table

Right click on point layer => Open attributes table => Select Advanced Filter (Expression)

enter image description here

Set the filter, you can do it on multiple columns with AND OR conditions

enter image description here

Select the records by clicking on left top corner => select Show Selected Features

enter image description here

You can the selected features on the map (yellow color)

enter image description here

  • Could I ask why you removed part of your answer which included an expression which could be used for the Select by expression tool? :) – Joseph Nov 12 '15 at 12:21
  • The things you deleted were helpful. I know about this feature to select by two ore more attributs from ArcGIS but I didn't find this in QGIS, so thank you for that. :) – Grete Samsa Nov 13 '15 at 8:25
  • I have included Select by expression tool again. Since @GreteSamsa was already aware of the tool I thought it wouldn't be of much help. As I understand from your comments it was helpful so included it. – Prayut0831 Nov 16 '15 at 6:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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