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!
You have several way, I use QGis 3.5
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.
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
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:
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)
Answered by helpmeimrubbish on March 10, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP