QgsFeature feature; QgsGeometry* geometry = feature.constGeometry(); if(geometry){ qDebug() << "Geometry type: " << geometry->type(); qDebug() << "Geometry: " << geometry->asWkt(); }
QgsFeature feature; QgsGeometry* geometry = feature.constGeometry(); if(geometry && geometry->type() == QgsWkbTypes::PolygonGeometry){ QgsPolygon* polygon = qobject_castThis code retrieves the geometry of a QgsFeature and checks if it is a polygon. If it is, it casts the geometry to a QgsPolygon object and calculates the area of the polygon using the area method. The area is then printed to the console. Both of these examples use the QgsFeature constGeometry member function to retrieve the geometry of a feature. The first example simply prints the type and WKT representation of the geometry, while the second example uses the geometry for spatial analysis by calculating the area of a polygon.(geometry); double area = polygon->area(); qDebug() << "Area of polygon: " << area; }