[GIS] Get extents of vector shape features in PyQGIS

extentspyqgis

i am just wondering if it is possible to iterate through vector features and return the extent per feature without clipping the vector shape?

The code looks like this and comes from the PyQgis-Documentation. How can i return the extent of every vector feature in a loop.

provider = vector.dataProvider()
            feat = QgsFeature()
            allAttrs = provider.attributeIndexes()
            provider.select(allAttrs)
            while provider.nextFeature(feat):
                geom = feat.geometry()
                # --> return extent or (xmin,ymin,xmax,ymax) ?

Best Answer

how about...

provider = vector.dataProvider()
        feat = QgsFeature()
        allAttrs = provider.attributeIndexes()
        provider.select(allAttrs)
        while provider.nextFeature(feat):
            geom = feat.geometry()
            rect = geom.boundingBox()  #get bounding box as QgsRectangle