// create a line geometry with two points QgsPoint startPoint(1, 2); QgsPoint endPoint(5, 6); QgsGeometry lineGeometry = QgsGeometry::fromPolyline({startPoint, endPoint});
// create a polygon geometry with three points QgsPoint point1(1, 2); QgsPoint point2(5, 6); QgsPoint point3(7, 8); QVectorIn these examples, we create two different types of geometries using the QgsGeometry type: a line with two points, and a polygon with three points in a counter-clockwise order. The examples highlight how simple it is to create geometries using the QgsGeometry type using the factory methods fromPolyline and fromPolygonXY. The QgsGeometry type is part of the QGIS Core library that comes packaged with the QGIS application.points = {point1, point2, point3}; QgsGeometry polyGeometry = QgsGeometry::fromPolygonXY({points});