QgsGeometry *polygon = QgsGeometry::fromWkt("POLYGON((0 0,0 10,10 10,10 0,0 0))"); const QgsGeos::Geometry *geosGeom = polygon->constGet< QgsGeos::Geometry >(); double area = geosGeom->area(); qDebug() << "Polygon area: " << area;
QgsGeometry *point = QgsGeometry::fromWkt("POINT(5 10)"); const QgsPoint *centroid = point->constGet< QgsPoint >(); qDebug() << "Point centroid: " << centroid->x() << ", " << centroid->y();
QgsRasterLayer *layer = new QgsRasterLayer("path/to/raster.tif", "Raster Layer", "gdal"); const QgsRasterBlock const *block = layer->dataProvider()->constGetRasterBlock(0, 0); qDebug() << "Pixel value at (0, 0): " << block->value(0, 0);In this example, we create a QgsRasterLayer object representing a raster file, then use constGet to retrieve a const pointer to a QgsRasterBlock object representing the data in the top-left corner of the raster. We then print the pixel value at (0, 0) to the console. Package library: QGIS + GDAL