3

I have a table with three columns that I'm interested in: X, Y and rotate. These specify the position and angle of a symbol. I want to find duplicates across these columns, so anything with the same X,Y co-ords which also has the same angle set. I can find duplicates in geometry but not by finding the angle as well. I thought along the line of a For loop with nested If statements, but am unsure how to set that up - I'm a bit of a beginner with PyQGIS. This the code I'm using to find the duplicates which was found elsewhere on this forum:

layer = subscriber_feed_layer
allfeatures={}
index = QgsSpatialIndex()
for ft in layer.getFeatures():
 allfeatures[ft.id()] = ft
 index.insertFeature(ft)
selection = []
for feat in layer.getFeatures():
 inGeom = feat.geometry()
 idsList = index.intersects(inGeom.boundingBox())
 if len(idsList) > 1:
 for id in idsList:
 selection.append(allfeatures[id])
layer.setSelectedFeatures([k.id() for k in selection])
nash
1,99615 silver badges19 bronze badges
asked Mar 10, 2017 at 12:09
4
  • find all the geometry duplicates, then look for symbol angle duplicates in that list? Commented Mar 10, 2017 at 12:13
  • Please, add a snippet of your code in order to receiving potential answers. As it's currently written, it's hard to give you any help. Commented Mar 10, 2017 at 12:18
  • This is the code I'm using to find the geometry duplicates: Commented Mar 10, 2017 at 12:41
  • @K.Osborne are you dealing with point features? Is "rotate" a field of your layer? Commented Mar 10, 2017 at 14:39

1 Answer 1

0

After finding the geometry duplicates, I've used a dictionary to find the same angle among them. Assuming that 'rotate' is the name of the field in your layer containing the angle of symbol, I've made a few changes to the code. Following should work for you -

layer = subscriber_feed_layer
allfeatures={}
index = QgsSpatialIndex()
for ft in layer.getFeatures():
 allfeatures[ft.id()] = ft
 index.insertFeature(ft)
selection = []
for feat in layer.getFeatures():
 inGeom = feat.geometry()
 idsList = index.intersects(inGeom.boundingBox())
 if len(idsList) > 1:
 d = {}
 for id in idsList:
 rot_ang = allfeatures[id]['rotate']
 if rot_ang in d:
 selection.append(allfeatures[id])
 selection.append(allfeatures[ d[rot_ang] ])
 else:
 d[rot_ang] = id
layer.setSelectedFeatures([k.id() for k in selection])
answered Mar 10, 2017 at 18:03
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.