Polygon from QgsPoints - QGIS 3.8 python

by César Arquero   Last Updated September 11, 2019 16:22 PM

I'm trying to create a polygon layer from 4 points that I have already defined. There issue here is that I'm always getting the following error:

AttributeError: type object 'QgsGeometry' has no attribute 'fromPolygon'

These are the points (printed in console):

print (points)
<QgsPoint: Point (546016.50083752069622278 4760165.85990538075566292)>
<QgsPoint: Point (535433.25716883409768343 4749582.61623669415712357)>
<QgsPoint: Point (559882.5150161839555949 4746299.84572671726346016)>
<QgsPoint: Point (549299.27134749735705554 4735716.60205803066492081)>

And here is the code that produces the error above:

layer = QgsVectorLayer(str('Polygon?crs='+crs), 'polygon' , 'memory')
prov = layer.dataProvider()
points = [H1V1p,H1V2p,H2V1p,H2V2p]
feat = QgsFeature()
feat.setGeometry(QgsGeometry.fromPolygon([points]))
prov.addFeatures([feat])
layer.updateExtents()
QgsMapLayerRegistry.instance().addMapLayers([layer])


Related Questions


Updated September 29, 2018 02:22 AM

Updated January 10, 2019 15:22 PM

Updated December 06, 2017 15:22 PM

Updated September 26, 2018 13:22 PM

Updated January 24, 2019 22:22 PM