1

The problem im having is that when I select the points, I cannot get a sorted list in order of selection, so the polygon ends up being created in unusual shape. the important code is below.

def startSelection(self):
    for lay in self.iface.mapCanvas().layers():
        if self.dlg.comboBox_2.currentText() == lay.name():
            self.iface.setActiveLayer(lay)
            self.iface.actionSelect().trigger()

def CreatePolygonLayer(self):
    points=[]
    for ft in self.iface.activeLayer().selectedFeatures():
        pt=QgsPointXY(ft.geometry().asPoint().x(),ft.geometry().asPoint().y())
        points.append(pt)

    layer=QgsVectorLayer('Polygon?crs=EPSG:32736','New Polygons','memory')
    b=QgsFeature()
    b.setGeometry(QgsGeometry.fromPolygonXY([points]))

    layer.dataProvider().addFeatures([b])
    QgsProject.instance().addMapLayers([layer])

So I'm building a QGIS plugin to create a polygon from selected points.

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
GISSIAH
  • 11
  • 1
  • you can just take the function 'CreatePolygonLayer' and use in the qgis python editor but you'll have to select the features manually – GISSIAH May 26 '20 at 10:58
  • All you need is Delaunay triangulation (and possibly a dissolve), you can run it through the processing module in PyQGIS. See here: https://gis.stackexchange.com/questions/39205/converting-point-sets-to-polygon-boundaries – 15Step May 26 '20 at 12:10

0 Answers0