I would like to retrieve a polygon's geometry from a layer to use it in a cql_filter. Right now, I'm using the code below. It is working, however, it's creating a rectangular geometry out of the polygon.
# Get the polygon layer
polygon_layer = QgsProject.instance().mapLayersByName(layer_name)[0]
# Get the extent of the polygon layer
extent = polygon_layer.extent()
# Create a polygon geometry from the extent
polygon = QgsGeometry.fromRect(extent)
I've tried searching online and reading the QGIS API documentation but I couldn't find what I'm looking for...
layer.extent()
method gives you a rectangle bounding the layer. Your question is unclear.TypeError: MultiPolygon geometry cannot be converted to a polygon. Only single polygon or curve polygon types are permitted.