from qgis.core import QgsGeometry # Specify polygon geometries as XY tuples poly1 = [(0,0), (0,10), (10,10), (10,0), (0,0)] poly2 = [(10,0), (10,10), (20,10), (20,0), (10,0)] # Create multi-polygon geometry geom = QgsGeometry.fromMultiPolygonXY([[poly1,], [poly2,]])
from qgis.core import QgsGeometry # Specify polygon geometry as XY tuples poly = [(0,0), (0,10), (10,10), (10,0), (0,0)] # Create polygon geometry geom = QgsGeometry.fromMultiPolygonXY([[poly,]])In both examples, we use the fromMultiPolygonXY method to create a QgsGeometry object from a list of polygon geometries specified as XY tuples. We pass the list to the method as a list of lists, with each inner list representing a polygon. The resulting QgsGeometry object can be used for further spatial analysis or display in a QGIS map. The package library for QgsGeometry and the fromMultiPolygonXY method is qgis.core, which is part of the QGIS Python API.