polygon = [(0,0), (0,1), (1,1), (1,0)] # list of vertices of a square polygon qgs_polygon = QgsGeometry.fromPolygon([polygon]) # create QgsGeometry from the polygon
layer = QgsProject.instance().mapLayersByName("my_layer")[0] # get a reference to a QGIS layer features = layer.getFeatures() # get all features from the layer for feature in features: polygon = feature.geometry().asPolygon() # get the polygon geometry of a feature qgs_polygon = QgsGeometry.fromPolygon([polygon]) # create QgsGeometry from the polygonThis code loops through all features of a QGIS layer, gets the polygon geometry of each feature, and creates a QgsGeometry from the polygon. The package library for QgsGeometry is qgis.core.