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!