TransWikia.com

Removing both sets of duplicate points

Geographic Information Systems Asked on March 10, 2021

I’m trying to create points on the edges of polygons.

So far I have converted the polygons to lines, then exploded the lines, then ran the following code which plots a point in the middle of the lines.

layer = iface.activeLayer()
temp = QgsVectorLayer("Point?crs=epsg:27700", "result", "memory")

temp.startEditing()
attrs = layer.dataProvider().fields().toList()
temp_prov = temp.dataProvider()
temp_prov.addAttributes(attrs)
temp.updateFields()

for elem in layer.getFeatures():
    feat = QgsFeature()
    geom = elem.geometry().interpolate(elem.geometry().length()/2)
    feat.setGeometry(geom)
    feat.setAttributes(elem.attributes())
    temp.addFeatures([feat])
    temp.updateExtents()

temp.commitChanges()
QgsProject.instance().addMapLayer(temp)

I have some polygons which are adjoined, sometimes several squares in a row.

I’ve noticed that each polygon still has a separate line, even though they’re adjoining polygons if that makes sense?

I want to remove the points where two polygons adjoin, and so therefore I just want to remove all instances where there’s duplicate points/lines. So not just remove duplicates so there’s one left, but remove both instances of duplicates.

Hope that makes sense and someone can help!

2 Answers

You have several way, I use QGis 3.5

  1. In the processing toolbox, go to vector general > delete duplicate geometries. Then select your layer and as output you will have a new "cleaned" layer.

  2. You can also use the Topology checker plugin and then you check for duplicates geometries.

In the first method, QGis will do everything automatically and in the second one, you will do it manually. You have many other method to check the topology and then delete duplicates, like for example check geometries

See below the interface of the topology checker

enter image description here Hope this help,

Answered by Yannick Arthur DOUNGMO on March 10, 2021

I've worked out a way to do this - although it does not involve deleting all duplicate points (including the 'all but one' normally left by duplicate points.

Instead I have:

  • Created a buffer around the polygon layer and dissolved the result
  • Changed the buffered polygon layer to lines
  • Exploded lines
  • Ran this code:
layer = iface.activeLayer()
temp = QgsVectorLayer("Point?crs=epsg:27700", "result", "memory")

temp.startEditing()

attrs = layer.dataProvider().fields().toList()
temp_prov = temp.dataProvider()
temp_prov.addAttributes(attrs)
temp.updateFields()

for elem in layer.getFeatures():
  feat = QgsFeature()
  geom = elem.geometry().interpolate(elem.geometry().length() / 2) 
  feat.setGeometry(geom)
  feat.setAttributes(elem.attributes())
  temp.addFeatures([feat])
  temp.updateExtents()

temp.commitChanges()
QgsProject.instance().addMapLayer(temp)
  • I have then used 'join by nearest feature' to retain the attributes in my original shapefile layer. Requires a bit of tidying up as first lot of features is from the buffered file, but does what I want it to do!

Answered by helpmeimrubbish on March 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP